wordpress数据库操作 批量删除/替换 媒体库/特色图/文章/发布状态

猫斯基  — WordPress基础开发


批量删除分类下的文章

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 = 1

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 = 1

批量替换内容和网址

UPDATE wp_posts SET post_content = REPLACE(post_content, '原内容' , '替换为的内容');

批量清空特色图片

global $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta 
WHERE meta_key = '_thumbnail_id'
" );

批量修改文章发布状态
WordPress文章状态分为:草稿’draft’,已发布’publish’,待审核’pending

UPDATE `wp_posts` SET `post_status` ='draft' WHERE (`post_status`='publish');

清空媒体库数据库

DELETE from wp_posts where post_type = 'attachment'

清空媒体数据库后,怎么删除媒体文件和文章之间的联系呢?使用下面的命令。

DELETE FROM `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes', '_wp_attachment_metadata', '_thumbnail_id')

阅读量:0 2020-12-24 00:07

返回顶部