admin管理员组文章数量:1122826
I have a site with loads of posts (news items). Some posts don't have featured images yet. Adding the images to those posts (few hundreds) is a tedious task. We basically want to add 1 and the same image to all the posts without a featured image.
Is there a way to do this in bulk? Like ADD 'this image' to ALL 'posts' (not pages) WHERE 'featured_image' is empty. I really hope there's a plugin for that. Can't find it though.
I have a site with loads of posts (news items). Some posts don't have featured images yet. Adding the images to those posts (few hundreds) is a tedious task. We basically want to add 1 and the same image to all the posts without a featured image.
Is there a way to do this in bulk? Like ADD 'this image' to ALL 'posts' (not pages) WHERE 'featured_image' is empty. I really hope there's a plugin for that. Can't find it though.
Share Improve this question asked May 31, 2022 at 8:45 RickRick 1116 bronze badges 1- Requests for plugin recommendations are off topic here - and a plugin wouldn't be the right approach anyway. Modify your code to check for the existence of a featured images, and if there isn't one, show the placeholder. – vancoder Commented Jun 6, 2022 at 22:05
2 Answers
Reset to default 2you can use this plugins as you like :
https://wordpress.org/plugins/default-featured-image/
https://wordpress.org/plugins/auto-post-thumbnail/
The featured image ID is stored in wp_postmeta with a meta_key called _thumbnail_id.
So you can retrieve all posts without a featured image like that:
$args = array(
'post_type' => 'post', // Change this to your post type if needed
'posts_per_page' => -1, // Get all posts
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS', // This checks if the post doesn't have a featured image
),
),
);
$posts = get_posts($args);
To assign a specific featured image (in this case, image ID 123) to each post do:
foreach ($posts as $post) {
set_post_thumbnail($post->ID, 123);
}
References
https://stackoverflow.com/a/28643825/2456038
本文标签: Bulkadd featured images in posts with no featured image
版权声明:本文标题:Bulk-add featured images in posts with no featured image 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297395a1930002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论