![](https://i-blog.csdnimg.cn/blog_migrate/11eaf90da9981d544ce02bd3b6d509c3.png)
wordpress批量导入
Recently one of our readers asked us how they can bulk remove featured images from posts in WordPress? At WPBeginner, we have discussed featured images (post thumbnails) many times. We showed you how to add featured images in WordPress, how to add new image sizes in WordPress, how to regenerate thumbnails, we even showed you how to add multiple featured images to a post in WordPress. In this article we will show you how to bulk remove featured images from posts in WordPress.
最近,我们的一位读者问我们如何从WordPress帖子中批量删除特色图片? 在WPBeginner,我们已经讨论了很多特色图片(缩略图)。 我们向您展示了如何在WordPress中添加特色图片 ,如何在WordPress中添加新图片尺寸 ,如何重新生成缩略图 ,甚至还向您展示了如何向WordPress中的帖子添加多个特色图片 。 在本文中,我们将向您展示如何从WordPress帖子中批量删除特色图片。
批量删除帖子缩略图或精选图片的问题 (The Problem With Bulk Removal of Post Thumbnails or Featured Images)
Unfortunately, by default you can only remove featured images by editing each post and removing the featured image. Now if a user has hundreds of posts with featured images, then removing them one by one can be a very time consuming task. Instead, we are going to try a different approach. We will run a database query and unset the featured images on all posts.
不幸的是,默认情况下,您只能通过编辑每个帖子并删除特色图像来删除特色图像。 现在,如果用户有数百篇带有特色图片的帖子,那么将它们一一删除可能是非常耗时的任务。 相反,我们将尝试另一种方法。 我们将运行数据库查询,并取消所有帖子的特色图片。
Before you proceed, please note that the code below will remove featured images from all posts on your WordPress site by simply just pasting. Also note that this code will not delete any of your uploaded images, they will still be available in Media Library and you can reuse them anytime.
在继续之前,请注意,下面的代码只需粘贴即可从WordPress网站上的所有帖子中删除精选图片。 另请注意,此代码不会删除您上传的任何图像,它们仍将在Media Library中可用,您可以随时重复使用它们。
All you need to do is copy and paste this code in your theme’s functions.php
file.
您需要做的就是将这段代码复制并粘贴到主题的functions.php
文件中。
global $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
That’s all. As soon as you save your functions.php file this script will run a database query and remove featured images from all posts.
就这样。 一旦保存了functions.php文件,该脚本将运行数据库查询并从所有帖子中删除特色图像。
Important: Please remove this code immediately after saving your functions.php file. You will not be able to set featured images in WordPress as this code will keep removing featured images from posts.
重要提示:请保存您的functions.php文件后立即删除此代码。 您将无法在WordPress中设置特色图片,因为此代码将不断从帖子中删除特色图片。
We hope this article helped you save some time and allowed you to bulk remove featured images from WordPress posts. For questions and feedback please leave a comment below.
我们希望本文能帮助您节省一些时间,并允许您从WordPress帖子中批量删除特色图片。 对于问题和反馈,请在下面留下评论。
Source: Kaiser
资料来源: Kaiser
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-bulk-remove-featured-images-from-posts-in-wordpress/
wordpress批量导入