Filter article that has featured image to shown on homepage [duplicate]
-
31-12-2020 - |
Question
How do I display article that has featured image uploaded?
I using premium theme. I found that all of the themes don't have this feature.
Am I need to configure this in php file?
Or there is another alternative way to fix this?
Hope this will not off topic.
I tried to add 'meta_key' => '_thumbnail_id'
in the script below, but not working.
<div class="grids entries">
<?php
$cats_to_show = get_sub_field( 'category_posts_per_page');
$cat_id = get_sub_field( 'category_section_name' );
$ti_cat_posts = new WP_Query(
array(
'posts_per_page' => 5,
'cat' => $cat_id,
'no_found_rows' => true,
)
);
became
<div class="grids entries">
<?php
$cats_to_show = get_sub_field( 'category_posts_per_page');
$cat_id = get_sub_field( 'category_section_name' );
$ti_cat_posts = new WP_Query(
array(
'posts_per_page' => 5,
'cat' => $cat_id,
'meta_key' => '_thumbnail_id' // Added
'no_found_rows' => true,
)
);
Solution
If you are trying to limit the home page to display only posts that have a featured image, you'll need to modify the post query being used to generate that page.
With a premium theme it may be best to consult the theme's author first, to see if there is a configuration option or other easy method built-in to do what you want.
Otherwise, you may be able to create a child theme that modifies that query via a filter (perhaps using has_post_thumbnail()
, see https://developer.wordpress.org/reference/functions/has_post_thumbnail/) or much less desirably, by modifying the logic in the premium theme itself.