Add option to hide a story in lists

This commit is contained in:
Tetrakern 2023-05-07 01:45:42 +02:00
parent c1959ceceb
commit e9f8695ff6
9 changed files with 125 additions and 25 deletions

View File

@ -232,7 +232,7 @@ Fictioneer customizes WordPress by using as many standard action hooks as possib
| `login_form` | `fictioneer_after_logout_cleanup` | `login_form` | `fictioneer_after_logout_cleanup`
| `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content` | `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content`
| `personal_options_update` | `fictioneer_update_admin_user_profile`, `fictioneer_update_my_user_profile` | `personal_options_update` | `fictioneer_update_admin_user_profile`, `fictioneer_update_my_user_profile`
| `pre_get_posts` | `fictioneer_extend_search_query`, `fictioneer_extend_taxonomy_pages`, `fictioneer_limit_authors_to_own_posts_and_pages`, `fictioneer_remove_unlisted_chapter_from_search` | `pre_get_posts` | `fictioneer_extend_search_query`, `fictioneer_extend_taxonomy_pages`, `fictioneer_limit_authors_to_own_posts_and_pages`, `fictioneer_remove_unlisted_from_search`
| `preprocess_comment` | `fictioneer_preprocess_comment` | `preprocess_comment` | `fictioneer_preprocess_comment`
| `save_post` | `fictioneer_create_sitemap`, `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships` | `save_post` | `fictioneer_create_sitemap`, `fictioneer_refresh_chapters_schema`, `fictioneer_refresh_chapter_schema`, `fictioneer_refresh_collections_schema`, `fictioneer_refresh_post_caches`, `fictioneer_refresh_post_schema`, `fictioneer_refresh_recommendations_schema`, `fictioneer_refresh_recommendation_schema`, `fictioneer_refresh_stories_schema`, `fictioneer_refresh_story_schema`, `fictioneer_save_seo_metabox`, `fictioneer_save_word_count`, `fictioneer_track_chapter_and_story_updates`, `fictioneer_update_modified_date_on_story_for_chapter`, `fictioneer_update_shortcode_relationships`
| `show_user_profile` | `fictioneer_custom_profile_fields` | `show_user_profile` | `fictioneer_custom_profile_fields`

View File

@ -129,16 +129,16 @@
"class": "", "class": "",
"id": "" "id": ""
}, },
"message": "Sticky in all lists", "message": "Sticky in lists",
"default_value": 0, "default_value": 0,
"ui": 0, "ui": 0,
"ui_on_text": "", "ui_on_text": "",
"ui_off_text": "" "ui_off_text": ""
}, },
{ {
"key": "field_60ecb1ba18b2b", "key": "field_6456dc4618338",
"label": "", "label": "",
"name": "fictioneer_story_no_epub", "name": "fictioneer_story_hidden",
"aria-label": "", "aria-label": "",
"type": "true_false", "type": "true_false",
"instructions": "", "instructions": "",
@ -149,7 +149,7 @@
"class": "", "class": "",
"id": "" "id": ""
}, },
"message": "Disable ePUB download", "message": "Hide story in lists",
"default_value": 0, "default_value": 0,
"ui": 0, "ui": 0,
"ui_on_text": "", "ui_on_text": "",
@ -255,6 +255,26 @@
"ui_on_text": "", "ui_on_text": "",
"ui_off_text": "" "ui_off_text": ""
}, },
{
"key": "field_60ecb1ba18b2b",
"label": "",
"name": "fictioneer_story_no_epub",
"aria-label": "",
"type": "true_false",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "Disable ePUB download",
"default_value": 0,
"ui": 0,
"ui_on_text": "",
"ui_off_text": ""
},
{ {
"key": "field_636d81d34cab1", "key": "field_636d81d34cab1",
"label": "Custom Story CSS", "label": "Custom Story CSS",
@ -294,5 +314,5 @@
"active": true, "active": true,
"description": "", "description": "",
"show_in_rest": 0, "show_in_rest": 0,
"modified": 1676250543 "modified": 1683414548
} }

View File

@ -164,34 +164,47 @@ if ( ! function_exists( 'fcn_keyword_search_authors_input' ) ) {
// ============================================================================= // =============================================================================
/** /**
* Remove unlisted chapters from search results * Remove unlisted chapters and stories from search results
* *
* @since 5.0 * @since 5.2.4
* *
* @param WP_Query $query The query. * @param WP_Query $query The query.
*/ */
function fictioneer_remove_unlisted_chapter_from_search( $query ) { function fictioneer_remove_unlisted_from_search( $query ) {
// Only for search queries on the frontend... // Only for search queries on the frontend...
if ( ! is_admin() && $query->is_main_query() && $query->is_search ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search ) {
$query->set( $query->set(
'meta_query', 'meta_query',
array( array(
'relation' => 'OR', 'relation' => 'AND',
array( array(
'key' => 'fictioneer_chapter_hidden', 'relation' => 'OR',
'compare' => 'NOT EXISTS', array(
'key' => 'fictioneer_chapter_hidden',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'fictioneer_chapter_hidden',
'value' => '0'
)
), ),
array( array(
'key' => 'fictioneer_chapter_hidden', 'relation' => 'OR',
'value' => '0', array(
'compare' => '=', 'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
)
) )
) )
); );
} }
} }
add_action( 'pre_get_posts' ,'fictioneer_remove_unlisted_chapter_from_search', 10 ); add_action( 'pre_get_posts' ,'fictioneer_remove_unlisted_from_search', 10 );
/** /**
* Extend search query with custom input * Extend search query with custom input

View File

@ -105,7 +105,6 @@ if ( ! function_exists( 'fictioneer_create_sitemap' ) ) {
foreach( $pages as $post ) { foreach( $pages as $post ) {
$template = get_page_template_slug( $post->ID ); $template = get_page_template_slug( $post->ID );
if ( in_array( $template, ['user-profile.php', 'single-bookmarks.php'] ) ) continue; if ( in_array( $template, ['user-profile.php', 'single-bookmarks.php'] ) ) continue;
$type = get_post_type( $post );
$frequency = 'yearly'; $frequency = 'yearly';
$lastmod = get_the_modified_date( 'c', $post->ID ); $lastmod = get_the_modified_date( 'c', $post->ID );
$sitemap .= fictioneer_url_node( get_permalink( $post->ID ), $lastmod, 'yearly' ); $sitemap .= fictioneer_url_node( get_permalink( $post->ID ), $lastmod, 'yearly' );
@ -153,13 +152,26 @@ if ( ! function_exists( 'fictioneer_create_sitemap' ) ) {
$stories = $last_saved_type == 'fcn_story' ? false : get_transient( 'fictioneer_sitemap_stories' ); $stories = $last_saved_type == 'fcn_story' ? false : get_transient( 'fictioneer_sitemap_stories' );
if ( ! $stories ) { if ( ! $stories ) {
$stories = get_posts( array( $stories = get_posts(
'post_type' => 'fcn_story', array(
'post_status' => array( 'publish' ), 'post_type' => 'fcn_story',
'orderby' => 'date', 'post_status' => array( 'publish' ),
'order' => 'DESC', 'orderby' => 'date',
'numberposts' => '2000' 'order' => 'DESC',
)); 'numberposts' => '2000',
array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
)
)
)
);
set_transient( 'fictioneer_sitemap_stories', $stories ); set_transient( 'fictioneer_sitemap_stories', $stories );
} }

View File

@ -32,6 +32,17 @@ $query_args = array(
'orderby' => 'meta_value ' . $args['orderby'], 'orderby' => 'meta_value ' . $args['orderby'],
'order' => $args['order'] ?? 'desc', 'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'], 'posts_per_page' => $args['count'],
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
),
'no_found_rows' => true 'no_found_rows' => true
); );

View File

@ -32,6 +32,17 @@ $query_args = array(
'orderby' => 'meta_value ' . $args['orderby'], 'orderby' => 'meta_value ' . $args['orderby'],
'order' => $args['order'] ?? 'desc', 'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'], 'posts_per_page' => $args['count'],
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
),
'no_found_rows' => true 'no_found_rows' => true
); );

View File

@ -38,6 +38,17 @@ $query_args = array(
'orderby' => 'meta_value', 'orderby' => 'meta_value',
'order' => $args['order'] ?? 'desc', 'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'] + 4, // Little buffer in case of no viable chapters 'posts_per_page' => $args['count'] + 4, // Little buffer in case of no viable chapters
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
),
'no_found_rows' => true, 'no_found_rows' => true,
'update_post_term_cache' => false 'update_post_term_cache' => false
); );

View File

@ -40,6 +40,17 @@ $query_args = array(
'orderby' => 'meta_value', 'orderby' => 'meta_value',
'order' => $args['order'] ?? 'desc', 'order' => $args['order'] ?? 'desc',
'posts_per_page' => $args['count'] + 4, // Little buffer in case of no viable chapters 'posts_per_page' => $args['count'] + 4, // Little buffer in case of no viable chapters
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
),
'no_found_rows' => true 'no_found_rows' => true
); );

View File

@ -27,7 +27,18 @@
'orderby' => 'meta_value modified', 'orderby' => 'meta_value modified',
'order' => 'DESC', 'order' => 'DESC',
'paged' => $page, 'paged' => $page,
'posts_per_page' => get_option( 'posts_per_page', 8 ) 'posts_per_page' => get_option( 'posts_per_page', 8 ),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'fictioneer_story_hidden',
'value' => '0'
),
array(
'key' => 'fictioneer_story_hidden',
'compare' => 'NOT EXISTS'
),
)
); );
// Filter query arguments // Filter query arguments