What filter / hook should I use?
You can use the pre_get_posts
action hook.
Following Tom’s comment on the question about querying for what you want, maybe set meta_query
to _thumbnail_id
.
I would also (
group )
the conditionals to read:
“Is both not admin and is main query, AND is either home, category, or archive.”
add_action( 'pre_get_posts', 'thumbnails_only' );
function thumbnails_only( $query ) {
if ( ( ! $query->is_admin && $query->is_main_query() ) && ( $query->is_home() || $query->is_category() || $query->is_archive() ) ) {
$meta_query = array(
array(
'key' => '_thumbnail_id',
)
);
$query->set( 'meta_query', $meta_query );
}
}
may want to replace is_home()
with is_front_page()
depending on your site settings.