From e9f8695ff63859d95530827220b5f0d0a0646c38 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Sun, 7 May 2023 01:45:42 +0200 Subject: [PATCH] Add option to hide a story in lists --- DEVELOPMENT.md | 2 +- .../acf/acf-json/group_5d6306e3a620a.json | 30 ++++++++++++++--- includes/functions/_search.php | 33 +++++++++++++------ includes/functions/_sitemap.php | 28 +++++++++++----- partials/_latest-stories-compact.php | 11 +++++++ partials/_latest-stories.php | 11 +++++++ partials/_latest-updates-compact.php | 11 +++++++ partials/_latest-updates.php | 11 +++++++ stories.php | 13 +++++++- 9 files changed, 125 insertions(+), 25 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 35b84bb2..855aeff6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -232,7 +232,7 @@ Fictioneer customizes WordPress by using as many standard action hooks as possib | `login_form` | `fictioneer_after_logout_cleanup` | `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content` | `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` | `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` diff --git a/includes/acf/acf-json/group_5d6306e3a620a.json b/includes/acf/acf-json/group_5d6306e3a620a.json index 883aed04..37c09c81 100644 --- a/includes/acf/acf-json/group_5d6306e3a620a.json +++ b/includes/acf/acf-json/group_5d6306e3a620a.json @@ -129,16 +129,16 @@ "class": "", "id": "" }, - "message": "Sticky in all lists", + "message": "Sticky in lists", "default_value": 0, "ui": 0, "ui_on_text": "", "ui_off_text": "" }, { - "key": "field_60ecb1ba18b2b", + "key": "field_6456dc4618338", "label": "", - "name": "fictioneer_story_no_epub", + "name": "fictioneer_story_hidden", "aria-label": "", "type": "true_false", "instructions": "", @@ -149,7 +149,7 @@ "class": "", "id": "" }, - "message": "Disable ePUB download", + "message": "Hide story in lists", "default_value": 0, "ui": 0, "ui_on_text": "", @@ -255,6 +255,26 @@ "ui_on_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", "label": "Custom Story CSS", @@ -294,5 +314,5 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1676250543 + "modified": 1683414548 } \ No newline at end of file diff --git a/includes/functions/_search.php b/includes/functions/_search.php index 4107d6c9..fb41e75d 100644 --- a/includes/functions/_search.php +++ b/includes/functions/_search.php @@ -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. */ -function fictioneer_remove_unlisted_chapter_from_search( $query ) { +function fictioneer_remove_unlisted_from_search( $query ) { // Only for search queries on the frontend... if ( ! is_admin() && $query->is_main_query() && $query->is_search ) { $query->set( 'meta_query', array( - 'relation' => 'OR', + 'relation' => 'AND', array( - 'key' => 'fictioneer_chapter_hidden', - 'compare' => 'NOT EXISTS', + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ) ), array( - 'key' => 'fictioneer_chapter_hidden', - 'value' => '0', - 'compare' => '=', + 'relation' => 'OR', + array( + '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 diff --git a/includes/functions/_sitemap.php b/includes/functions/_sitemap.php index 559a08ff..dfac0db1 100644 --- a/includes/functions/_sitemap.php +++ b/includes/functions/_sitemap.php @@ -105,7 +105,6 @@ if ( ! function_exists( 'fictioneer_create_sitemap' ) ) { foreach( $pages as $post ) { $template = get_page_template_slug( $post->ID ); if ( in_array( $template, ['user-profile.php', 'single-bookmarks.php'] ) ) continue; - $type = get_post_type( $post ); $frequency = 'yearly'; $lastmod = get_the_modified_date( 'c', $post->ID ); $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' ); if ( ! $stories ) { - $stories = get_posts( array( - 'post_type' => 'fcn_story', - 'post_status' => array( 'publish' ), - 'orderby' => 'date', - 'order' => 'DESC', - 'numberposts' => '2000' - )); + $stories = get_posts( + array( + 'post_type' => 'fcn_story', + 'post_status' => array( 'publish' ), + 'orderby' => 'date', + '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 ); } diff --git a/partials/_latest-stories-compact.php b/partials/_latest-stories-compact.php index b760acd3..65c62dd5 100644 --- a/partials/_latest-stories-compact.php +++ b/partials/_latest-stories-compact.php @@ -32,6 +32,17 @@ $query_args = array( 'orderby' => 'meta_value ' . $args['orderby'], 'order' => $args['order'] ?? 'desc', '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 ); diff --git a/partials/_latest-stories.php b/partials/_latest-stories.php index 2d625fa9..732589bf 100644 --- a/partials/_latest-stories.php +++ b/partials/_latest-stories.php @@ -32,6 +32,17 @@ $query_args = array( 'orderby' => 'meta_value ' . $args['orderby'], 'order' => $args['order'] ?? 'desc', '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 ); diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index 0648ab17..f75ba707 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -38,6 +38,17 @@ $query_args = array( 'orderby' => 'meta_value', 'order' => $args['order'] ?? 'desc', '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, 'update_post_term_cache' => false ); diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index 3396d338..6fba2fc8 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -40,6 +40,17 @@ $query_args = array( 'orderby' => 'meta_value', 'order' => $args['order'] ?? 'desc', '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 ); diff --git a/stories.php b/stories.php index 71d04473..bc4c5bc5 100644 --- a/stories.php +++ b/stories.php @@ -27,7 +27,18 @@ 'orderby' => 'meta_value modified', 'order' => 'DESC', '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