From 6b4b1eadb4337040ece1de672aeb731d2818c18f Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:24:44 +0200 Subject: [PATCH] Fix meta queries for non-existing fields Well, that was to be expected, really. Hope that were all... --- author.php | 22 +++++++++++++--- includes/functions/_utility.php | 22 +++++++++++++--- .../functions/schemas/_chapters_schema.php | 25 +++++++++++++++++-- includes/functions/users/_follows.php | 1 + partials/_latest-chapters-compact.php | 16 +++++++++--- partials/_latest-chapters.php | 16 +++++++++--- 6 files changed, 86 insertions(+), 16 deletions(-) diff --git a/author.php b/author.php index a109e30c..abb62033 100644 --- a/author.php +++ b/author.php @@ -74,12 +74,26 @@ $tabs['chapters'] = array( 'meta_query' => array( 'relation' => 'AND', array( - 'key' => 'fictioneer_chapter_hidden', - 'value' => '0' + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ) ), array( - 'key' => 'fictioneer_chapter_no_chapter', - 'value' => '0' + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'compare' => 'NOT EXISTS' + ) ) ) ), diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index 2a0da0a4..02d0352e 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -444,12 +444,26 @@ if ( ! function_exists( 'fictioneer_get_author_statistics' ) ) { 'meta_query' => array( 'relation' => 'AND', array( - 'key' => 'fictioneer_chapter_hidden', - 'value' => '0' + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ) ), array( - 'key' => 'fictioneer_chapter_no_chapter', - 'value' => '0' + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'compare' => 'NOT EXISTS' + ) ) ), 'update_post_term_cache' => false diff --git a/includes/functions/schemas/_chapters_schema.php b/includes/functions/schemas/_chapters_schema.php index a398344a..2ee2ecce 100644 --- a/includes/functions/schemas/_chapters_schema.php +++ b/includes/functions/schemas/_chapters_schema.php @@ -73,8 +73,29 @@ if ( ! function_exists( 'fictioneer_build_chapters_schema' ) ) { 'post_type' => 'fcn_chapter', 'post_status' => 'publish', 'meta_query' => array( - array( 'key' => 'fictioneer_chapter_hidden', 'compare' => '=', 'value' => 0, 'type' => 'numeric' ), - array( 'key' => 'fictioneer_chapter_no_chapter', 'compare' => '=', 'value' => 0, 'type' => 'numeric' ) + 'relation' => 'AND', + array( + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ) + ), + array( + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'value' => '0' + ), + array( + 'key' => 'fictioneer_chapter_no_chapter', + 'compare' => 'NOT EXISTS' + ) + ) ), 'orderby' => 'modified', 'order' => 'DESC', diff --git a/includes/functions/users/_follows.php b/includes/functions/users/_follows.php index fcbe76fd..6631f762 100644 --- a/includes/functions/users/_follows.php +++ b/includes/functions/users/_follows.php @@ -226,6 +226,7 @@ if ( ! function_exists( 'fictioneer_query_followed_chapters' ) ) { 'post_type' => 'fcn_chapter', 'post_status' => 'publish', 'meta_query' => array( + 'relation' => 'AND', array( 'key' => 'fictioneer_chapter_story', 'value' => $story_ids, diff --git a/partials/_latest-chapters-compact.php b/partials/_latest-chapters-compact.php index bef30472..fb845b21 100644 --- a/partials/_latest-chapters-compact.php +++ b/partials/_latest-chapters-compact.php @@ -43,10 +43,20 @@ $query_args = array( 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story - 'meta_key' => 'fictioneer_chapter_hidden', - 'meta_value' => 0, 'no_found_rows' => true, - 'update_post_term_cache' => false + 'update_post_term_cache' => false, + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => 0, + 'compare' => '=' + ) + ) ); // Author? diff --git a/partials/_latest-chapters.php b/partials/_latest-chapters.php index f5b0e67c..18de119f 100644 --- a/partials/_latest-chapters.php +++ b/partials/_latest-chapters.php @@ -44,10 +44,20 @@ $query_args = array( 'orderby' => $args['orderby'], 'order' => $args['order'], 'posts_per_page' => $args['count'] + 8, // Little buffer in case of unpublished parent story - 'meta_key' => 'fictioneer_chapter_hidden', - 'meta_value' => 0, 'no_found_rows' => true, - 'update_post_term_cache' => false + 'update_post_term_cache' => false, + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => 'fictioneer_chapter_hidden', + 'compare' => 'NOT EXISTS' + ), + array( + 'key' => 'fictioneer_chapter_hidden', + 'value' => 0, + 'compare' => '=' + ) + ) ); // Author?