I'm having hard times with showing only posts which have featured images using the loop. My PHP level is basic and any help will be really useful.
So basically this is my original code :
if( have_posts() ) {
while( have_posts() ) {
the_post();
get_template_part( 'inc/template-parts/content', $post_layout );
// and some other stuff
}
}
I tried the advice from this thread - How do I check if a post has a post thumbnail in WP_Query
?
But without any success. When I implement the code all posts disappear from the front page.
This is the code I tried:
$query = new WP_Query( $thumbs );
$thumbs = array(
'meta_query' => array( 'key' => '_thumbnail_id' )
);
if( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
get_template_part( 'inc/template-parts/content', $post_layout );
}
}
Any advice will be appreciated! Regards