🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

WordPress Bulk Delete Category Posts, Clear Featured Images, Modify Post Status

Sometimes website redesigns involve modifying a large number of posts, and manual operation is too time-consuming. Therefore, Naibabiji shares methods for WordPressBulk Delete Posts in CategoriesClear Post Featured Images, Replace ContentModify Post Publishing Statusmethods.Please note that the method shared in this article involves database operations; please back up first.

Bulk Delete Posts Under a Category

1. Use phpMyAdmin to log into your database backend and switch to your website's database. 2. Click SQL, copy the database command, and execute it.批量删除数据库文章The database command is as follows. The final 1792 represents the category ID you want to delete. You can determine the ID by hovering over the category in the URL.
delete
from
wp_posts 
using 
wp_posts,
wp_term_relationships,
wp_term_taxonomy 
where 
wp_posts.id=wp_term_relationships.object_id 
and 
wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
and 
wp_term_relationships.term_taxonomy_id = 1792
After execution, the result will be displayed, as shown in the figure below:批量删除数据库文章

Bulk Replace Content and URLs

If your website has changed its domain name or name, then the URLs and names inserted in your previous articles need to be modified. Manually modifying them is too troublesome; just use a plugin with a graphical interface, which is very simple.If you want to use a database command for replacement, use the following statement.
UPDATE wp_posts SET post_content = REPLACE(post_content, '原内容' , '替换为的内容');

Bulk Clear Featured Images

If some of your articles have featured images set while others do not, and after switching to a new theme, the featured images look ugly, you can use the following command to batch delete article featured image data (this will not delete the featured image files).Related articles on WordPress featured images:Insert the following code into the theme's functions.php file,Safe Method to Add Code to the functions.php File: Code Snippets
global $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta 
WHERE meta_key = '_thumbnail_id'
" );
After adding, visit the website and you will find that all article featured images have been cleared.Then delete the above code, otherwise you will never be able to add featured images.

Bulk Modify Post Publishing Status

WordPress article statuses are divided into: draft 'draft', published 'publish', pending review 'pending'. We can use the following command to batch modify article status changes.
UPDATE `wp_posts` SET `post_status` ='draft' WHERE (`post_status`='publish');
The above code means changing the post_status value in the wp_posts table to draft, which is the draft status. Which files to modify are determined by the post_status value being publish; only those that are publish (published) will be changed to draft.

Clear Media Library Database

If you need to clear WordPress media library information, you can execute the following commands in the database.
DELETE from wp_posts where post_type = 'attachment'
The above command can delete all media library information. If you want to query media library information, use the following command.
Select * from wp_posts where post_type = 'attachment';
After clearing the media database, how to delete the connection between media files and articles? Use the following command.
DELETE FROM `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes', '_wp_attachment_metadata', '_thumbnail_id')
If you only want to query the association between the media library and articles, then use the following command.
 SELECT * FROM  `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes',  '_wp_attachment_metadata',  '_thumbnail_id')
The above introducesWordPress batch delete category articles, clear featured images, modify article status methods. If you have other batch processing methods, feel free to share and discuss.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: