If you want to set a featured image on all wordpress posts that don’t already have a featured image set, then this mysql query can help:
INSERT INTO
wp_postmeta (post_id,meta_key,meta_value)
SELECT
p.ID, '_thumbnail_id', id_of_image_from_upload_table
FROM
wp_posts p
LEFT JOIN
wp_postmeta pm ON p.ID = pm.post_id
AND pm.meta_key = '_thumbnail_id'
WHERE
p.post_type IN ('post')
AND p.post_status IN ('publish')
AND pm.meta_key IS NULL
LIMIT 0 , 100000;
# please note that this query will fail; you have to replace ‘id_of_image_from_upload_table’ with the id of the image you uploaded.
To find that ID, upload an image to the media library, then run this query:
SELECT
ID
FROM
wp_posts
WHERE
post_type = 'attachment'
ORDER BY ID DESC
LIMIT 1;
You could join it all together and run it in a single query if you like..
Finally, update the postmeta table for entries who have a thumbnail image, but a null value:
update wp_postmeta set meta_value=id_of_image_from_upload_table where meta_key = '_thumbnail_id' and meta_value is null;
When you set a featured image on all wordpress posts it offers several benefits that enhance both the visual appeal and functionality of a website.
- Improved Visual Engagement: A featured image serves as the main visual representation of a post or page. It helps capture the attention of visitors, making the content more appealing and inviting. A visually compelling image can encourage users to click through and explore the content further.
- Better Social Sharing: When content is shared on social media platforms like Facebook, Twitter, or LinkedIn, the featured image is often displayed as part of the shared post. This boosts engagement on social media by providing a preview that encourages clicks and shares.
- Consistent Layout: Featured images create a more structured and professional-looking website by maintaining a consistent design. On blog pages or archives, featured images help create a uniform layout, making the site look organized and polished.
- SEO Benefits: Search engines like Google index images, and a properly tagged featured image can improve a post’s SEO. By using relevant images with alt tags, the post becomes more discoverable through both text and image search results.
Overall, setting a featured image boosts content visibility, user engagement, and SEO, making it an essential feature in WordPress.
Get the Plugin! Quickly set the featured image for all posts which don’t have one
- Get the plugin from the wordpress plugins directory
- Navigate to admin > Born Creative > Set Featured Images
- Click the ‘Select Image’ button
- Click the ‘Apply’ button that shows once you have selected an image
Enjoy a featured image on all your posts which were missing one!