WordPress如何使用SQL语句批量修改文章分类?

直接通过phpmyadmin管理工具进入操作,注意会报主键错误,解决方案是:在第一列增加一个主键列,取消默认主键列,修改完成后再回复原来设置
update wp_term_relationships
set term_taxonomy_id=2
WHERE term_taxonomy_id = '1' AND object_id IN (1,2,3)

 

参考sql语句:

SELECT tt.term_taxonomy_id FROM wp_term_taxonomy AS tt INNER JOIN wp_terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy ='category' AND t.term_id = 419;

UPDATE wp_term_relationships set term_taxonomy_id=176 WHERE term_taxonomy_id in (423,958,418,422,421,420,417,426);

SELECT * FROM `wp_term_relationships` WHERE term_taxonomy_id=419;
–1、先根据分类 获取term_id
SELECT * FROM `wp_terms` where slug=’fintech’;
–2、根据分类id查询对应目录和分类标签id term_taxonomy_id
SELECT * FROM `wp_term_taxonomy` WHERE term_id=419;
–3、根据分类id获取文章的关系,查询出文章综述,object_id
SELECT * FROM `wp_term_relationships` WHERE term_taxonomy_id=416;
–4、根据object_id查询 文章内容,post表
SELECT * FROM `wp_posts` WHERE id=86814
–联合查询语句
SELECT * FROM `wp_posts` WHERE id in (SELECT object_id FROM `wp_term_relationships` WHERE term_taxonomy_id=(SELECT tt.term_taxonomy_id FROM wp_term_taxonomy AS tt INNER JOIN wp_terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy =’category’ AND t.term_id =(SELECT term_id FROM `wp_terms` where slug=’fintech’)));
—166714
SELECT * FROM `wp_term_relationships` WHERE term_taxonomy_id=419 and object_id=166714;

UPDATE wp_term_relationships set term_taxonomy_id=176 where object_id in (SELECT object_id FROM `wp_term_relationships` WHERE term_taxonomy_id=419)and term_taxonomy_id=419;

SELECT count(object_id) FROM `wp_term_relationships` WHERE term_taxonomy_id=176;

SELECT * FROM `wp_term_relationships` WHERE object_id=162790;

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/297267.html

(0)
上一篇 2023年8月30日
下一篇 2023年8月30日

相关推荐

发表回复

登录后才能评论