diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index 256cf20950..27e7ba6a99 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -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 *