Exclude Posts from List if Not Featured image attached

Posted in: Newsmag
Post count: 26

That’s it. How can I exclude all no-featured-image posts from listings? I need to do this in the more optimized way, on Newsmag template running WordPress 4.2.1.

The thing is, where do I have to add this specific part to the WP Query?

$args = array(
'post_type' => 'post',
'posts_per_page' => 6,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
),
)
);

Thanks, really appreciating your great template.

Post count: 7909

Hi,

You can try to add that array in data source file before return $wp_query_args: http://screencast.com/t/NL677iaZz

Thanks!

Post count: 26

Hi Alin, thanks for your great support. I added the thing where you specified.

But, in your screenshot, the line does not match with the one in which I found the return $wp_query_args.

It is found twice (Around lines 450 and 550)

I added the following snippet in both of ’em:

//Custom QUERY to not load posts without Featured Images. Except for category Opinion
//if($wp_query_args['cat']!=859){ /* 859 ID of Categ: Opinion on LR. */
$wp_query_args['meta_query']=array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
);
//}

return $wp_query_args;

With the commented lines as shown (will use those once it is working fine.)
But, it is still loading all the posts as before.

Also, I disabled caching on wordpress, to make sure the page is being re-generated.

Where do the $wp_query_args affect in the first and second case?

Thanks Alin. Great work. Peace.

Post count: 26

[Remove this if possible, replied on the wrong topic] Sorry.

  • This reply was modified 11 years by nikau.
Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newsmag’ is closed to new topics and replies.