You can try to add
'meta_key' => '_thumbnail_id',
to your input arguments:
$args = array( 'numberposts' => 5,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'meta_key' => '_thumbnail_id',
);
to query only posts with thumbnails (i.e. featured images).
ps: instead of this structure:
if ( !has_post_thumbnail() ) {
continue;
} else {
}
you can in general use
if ( has_post_thumbnail() ) {
}
But you can now skip the if
-sentence part in the loop since you are now only fetching posts with featured images.
Related Posts:
- How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
- How to Fix HTTP Error When Uploading Images?
- How to retrieve image from URL and set as featured image/post thumbnail
- Set Featured Image Front Frontend Form
- oEmbed, thumbnails and wordpress
- Retrieve 1st image in post and set it as featured image, when post is saved/updated
- the_post_thumbnail scaling not hard cropping
- Featured Image Inherited from Parent Page
- Change wording of default thumbnail metabox
- Specific featured image for each category
- how to pull images with no add_theme_support(‘post_thumbnails’)
- Can WordPress crop only the post thumbnails?
- Query the post which have a thumbnail
- How to show a featured image as current?
- How can I get a different image size, if all I have is the link?
- Show current page featured image in sidebar
- wordpress responsive image srcset not working
- Importing featured image to posts, duplicates the image
- Remove dimensions from filename featured image
- How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?
- Use post thumbnail as div background
- How do I set the default “feature image” size?
- Featured Image missing in WordPress 3.2 Admin
- Post Thumbnails multiple sizes
- Change post thumbnail using front end post edit form
- Featured image thumbnail sometimes in content, sometimes changes header images
- Function to replace the url of featured images in the wordpress database?
- has_post_thumbnail gives always TRUE
- Displaying wordpress image size as array used for page builder
- Setting a default placeholder image WITHOUT link
- If I Regenerate Thumbnails, would WordPress delete the existing Thumbnails and replace them with ‘new copies’?
- how to use first post image as thumbnail on wordpress
- Make the first image the post thumbnail without setting it as the featured image
- set a chosen image-file-input as a featured image from wp frontend
- Aligning the thumbnail image
- How do get post thumbnail into plugin?
- Default Featured Image from Post content
- upload or auto setup feature photo by user avatar
- wp_get_attachment_image_src match smallest edge
- How to replace featured image upload option with the post media image option
- How to create resized versions of images added with wp_insert_attachment
- Can I insert the feature image inside the content, after any paragraph?
- Set Post Thumbnails in Percents
- WordPress returns old thumbnail size after changing media settings
- media-library: how to insert thumbnails with a fixed width, regardless of landscape/portrait orientation
- get_the_post_thumbnail() returns nothing?
- How to bring files from the upload directory to the media gallery?
- Image with large file size not cropping
- What can I do if I set a gif as featured image? no thumbnail when i share on facebook
- Can’t get post thumbnail to display in foreach loop
- Responsive scaling of image for the_post_thumbnail() [closed]
- Child Category Image
- Resizing thumbnails retrospectively
- Displaying caption with featured image
- upload image only
- How Do I Create A WordPress Secondary Featured Image Without A Plugin? [closed]
- Generating very small sized thumbnails from featured image
- a tricky question about featured image
- How risize a thumbnail?
- Where to add the_post_thumbnail( )
- Is wordpress compressing my images? if so, how to prevent it?
- Getting featured image with direct $wpdb within plugin
- WordPress get_categories & listing recent post thumbnail
- Edit Media – Edit Custom Sized Featured Images
- set_post_thumbnail_size not cropping featured images
- Making featured image to show on home page
- Multi post thumbnails doesn’t return anything
- Add filter on certain thumbnail sizes only
- WordPress featured image url rendering incorrectly when page is loaded causing image to break
- Where in functions.php to add this code so thumbnail images display?
- Adding thumbnails independent of images in blog posts
- Featured image size per post type
- featured image is not showing
- display div tag only if post has thumbnail
- How to exclude 150*150 Image to set as a thumbnail?
- Get featured image from post on RSS feed
- Issue with wordpress thumnails – same thumnail displayed everywhere
- the_post_thumbnail() for displaying page feautred image?
- Featured image size is being restricted–how can I troubleshoot and resolve?
- Smaller Size for featured images
- Featured image doesn’t appear in Blog index
- Allow ‘Set featured images’ to select multiple images
- Echo recent posts each with its own respective featured image
- Why wordpress doesn’t generate thumbnails?
- Force Regenerate Thumbnails Not Working
- Page featured image not showing on home page
- Featured Image of the post are gone after site move to another server
- Copy wp_postmeta from one database to another
- How can I retrieve a Featured Image thumbnail using only the Post_title?
- Mass/Bulk assign featured images to posts
- Worse thumbnail quality after GD library install
- Fetching full size featured image to insert in RSS Feed
- Change get_post_thumb responsively?
- Always generate thumbnail after sideloading image
- Hide feature image when is not populated
- Crop featured image by default
- add_theme_support( ‘post-thumbnails’, array( ‘post’)); is not uploading the file
- I would like my posts to pull my custom cropped thumbnail instead of creating its own thumbnail from Featured Image
- Missing thumbnails
- Get Thumbnails and Thumbnails URL from Media Manager