Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate category_name, cat and tag_id from ES query when tax_query set #2241

Merged
merged 7 commits into from
Jul 20, 2021
30 changes: 16 additions & 14 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
Expand Down Expand Up @@ -886,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'],
Expand Down