Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipeelia/f741e81b054332bf389a6f0f9c8ff043 to your computer and use it in GitHub Desktop.
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.
<?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