Created
March 24, 2022 11:26
-
-
Save felipeelia/f741e81b054332bf389a6f0f9c8ff043 to your computer and use it in GitHub Desktop.
Change the ElasticPress search query to match only content with a thumbnail set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Since ElasticPress 4.0, thumbnails are indexed in a separate field. | |
*/ | |
add_filter( | |
'ep_post_formatted_args', | |
function ( $formatted_args ) { | |
if ( empty( $_GET['has_image'] ) ) { | |
return $formatted_args; | |
} | |
$formatted_args['post_filter']['bool']['must'][] = array( | |
'exists' => array( | |
'field' => 'thumbnail', | |
), | |
); | |
return $formatted_args; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment