Skip to content

Commit

Permalink
Merge pull request #2462 from roborourke/patch-2
Browse files Browse the repository at this point in the history
Ensure array query parameters do not contain empty items
  • Loading branch information
felipeelia authored Dec 14, 2021
2 parents 287af71 + a876c36 commit 07f6dd2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,32 @@ public function format_args( $args, $wp_query ) {
);
$use_filters = false;

// Sanitize array query args. Elasticsearch will error if a terms query contains empty items like an
// empty string.
$keys_to_sanitize = [
'author__in',
'author__not_in',
'category__and',
'category__in',
'category__not_in',
'tag__and',
'tag__in',
'tag__not_in',
'tag_slug__and',
'tag_slug__in',
'post_parent__in',
'post_parent__not_in',
'post__in',
'post__not_in',
'post_name__in',
];
foreach ( $keys_to_sanitize as $key ) {
if ( ! isset( $args[ $key ] ) ) {
continue;
}
$args[ $key ] = array_filter( (array) $args[ $key ] );
}

/**
* Tax Query support
*
Expand Down

0 comments on commit 07f6dd2

Please sign in to comment.