How do I get posts that have a thumbnail in WP_Query? olatechproMarch 16, 20231 Views I want to grab the 5 most recent posts that have thumbnails. Post Views: 1 Related postsGet rid of this Strict Standards warningWooCommerce: get_current_screen not working with multi languageCan’t login on WordPressForce HTTPS using .htaccess – stuck in redirect loopWordPress: Ajax not working to insert, query and result dataHow Can I pass an image file to wp_handle_upload?
You should be able to call posts with a featured image with the following code: $thumbs = array( 'posts_per_page' => 5, 'meta_query' => array(array('key' => '_thumbnail_id')) ); $query = new WP_Query($thumbs); The code checks each post for the custom field _thumbnail_id, which is where the thumbnail image is stored. Log in to Reply
You should be able to call posts with a featured image with the following code:
The code checks each post for the custom field _thumbnail_id, which is where the thumbnail image is stored.