Clear Media Library Database
Sometimes, website redesigns involve modifying a large number of posts. Manual operation is too time-consuming, so Naibabiji Website Building Notes shares with you WordPress methods for:、
Batch deleting posts from a category directory,和
Clearing post featured images, replacing content,and modifying post publication status.
Please note: The methods shared in this article involve database operations. Please back up first.December 12, 2019
1. Use phpMyAdmin to log into your database backend and switch to your website's database. 2. Click on SQL, copy the database command, and then execute it.

The database command is as follows. The final number, 1792, represents the ID of the category directory you want to delete. You can determine this by hovering your mouse over the category directory and checking the ID information 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, it will tell you the result, as shown in the image below:

Batch Delete Posts Under a Category
If your website has changed its domain name or name, then the URLs and names inserted in your previous posts need to be modified. Manually modifying them is too troublesome. Use a plugin directly; it has a graphical interface and is very simple.
If you want to use a database command for replacement, it's the following statement.
UPDATE wp_posts SET post_content = REPLACE(post_content, '原内容' , '替换为的内容');
Batch Replace Content and URLs
If some of your posts have featured images set and others don't, and after switching to a new Theme, the featured images look ugly, you can use the following command to batch delete the post featured image data (it will not delete the featured image files).
WordPress Featured Image Related Articles:Insert the following code into the Theme's functions.php file.
Safe method to add code to the functions.php file: Code Snippetsglobal $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
After adding it, visit the website and you will find that all post featured images have been cleared.
Then delete the code above, otherwise you will never be able to add featured images.
Batch Clear Featured Images
WordPress post statuses are divided into: 'draft', 'publish', 'pending'. We can use the following command to batch modify post status changes.
UPDATE `wp_posts` SET `post_status` ='draft' WHERE (`post_status`='publish');
The meaning of the code above is to change the post_status value in the wp_posts table to 'draft' (draft status). Which files to modify is determined by the condition where the post_status value is 'publish'—only those that are 'publish' (published) will be changed to draft.
Batch Modify Post Publication Status
If you need to clear the information in the WordPress Media Library, 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 command below.
Select * from wp_posts where post_type = 'attachment';
After clearing the media database, how to delete the connection between media files and Posts? Use the command below.
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 Posts, then use the command below.
SELECT * FROM `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes', '_wp_attachment_metadata', '_thumbnail_id')The above introduces
WordPress Batch Delete Category Posts, Clear Featured Images, Modify Post Status Methods. If you have other batch processing methods, feel free to discuss.
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.