From c5ea33c7bb24756ec5a1cc7152f4a0010d82c65d Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Fri, 25 Jun 2021 08:43:49 -0600 Subject: [PATCH 1/3] Remove duplicate category_name, cat and tag_id from ES query when tax_query set --- includes/classes/Indexable/Post/Post.php | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index c8e5d85eee..27be2f73ea 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -825,20 +825,22 @@ public function format_args( $args, $wp_query ) { */ // Find root level taxonomies. - if ( isset( $args['category_name'] ) && ! empty( $args['category_name'] ) ) { - $args['tax_query'][] = array( - 'taxonomy' => 'category', - 'terms' => array( $args['category_name'] ), - 'field' => 'slug', - ); - } + if ( empty( $args['tax_query'] ) ) { + if ( isset( $args['category_name'] ) && ! empty( $args['category_name'] ) ) { + $args['tax_query'][] = array( + 'taxonomy' => 'category', + 'terms' => array( $args['category_name'] ), + 'field' => 'slug', + ); + } - if ( isset( $args['cat'] ) && ! empty( $args['cat'] ) ) { - $args['tax_query'][] = array( - 'taxonomy' => 'category', - 'terms' => array( $args['cat'] ), - 'field' => 'term_id', - ); + if ( isset( $args['cat'] ) && ! empty( $args['cat'] ) ) { + $args['tax_query'][] = array( + 'taxonomy' => 'category', + 'terms' => array( $args['cat'] ), + 'field' => 'term_id', + ); + } } if ( isset( $args['tag'] ) && ! empty( $args['tag'] ) ) { @@ -869,7 +871,7 @@ public function format_args( $args, $wp_query ) { $has_tag__and = true; } - if ( isset( $args['tag_id'] ) && ! empty( $args['tag_id'] ) && ! is_array( $args['tag_id'] ) ) { + if ( isset( $args['tag_id'] ) && ! empty( $args['tag_id'] ) && ! is_array( $args['tag_id'] ) && empty( $args['tax_query'] ) ) { // If you pass tag__in as a parameter, core adds the first // term ID as tag_id, so we only need to append it if we have From 495318785f12162488e1eddc85a9c23f28663807 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:15:28 -0600 Subject: [PATCH 2/3] Remove check for tags --- includes/classes/Indexable/Post/Post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index 27be2f73ea..d151a36935 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -871,7 +871,7 @@ public function format_args( $args, $wp_query ) { $has_tag__and = true; } - if ( isset( $args['tag_id'] ) && ! empty( $args['tag_id'] ) && ! is_array( $args['tag_id'] ) && empty( $args['tax_query'] ) ) { + if ( isset( $args['tag_id'] ) && ! empty( $args['tag_id'] ) && ! is_array( $args['tag_id'] ) ) { // If you pass tag__in as a parameter, core adds the first // term ID as tag_id, so we only need to append it if we have From d6be432612fadbcd69d9b3bd226fe376320f991c Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Tue, 29 Jun 2021 12:08:31 -0600 Subject: [PATCH 3/3] Move check towards when there is no tag__and set --- includes/classes/Indexable/Post/Post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index d151a36935..81671c97d8 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -888,7 +888,7 @@ function( $tax_query ) use ( $args ) { }, $args['tax_query'] ); - } else { + } elseif ( empty( $args['tax_query'] ) ) { $args['tax_query'][] = array( 'taxonomy' => 'post_tag', 'terms' => $args['tag_id'],