庆云php

庆云php

给wordpress的文章导入标签对应的标签,拿走不谢

PHP 0
给wordpress的文章导入标签对应的标签 -- wordpress导入标签 -- 插入标签,如果有标签了,则不插入失败 INSERT INTO `wp_terms`( `name`, `slug`, `term_group`) select a.name,a.slug,0 from (select '孩子' name, 'hz' slug ) a left join wp_terms b on a.name=b.name or a.slug=b.slug where b.name is null ; -- 插入标签对应的索引,有索引了插入为空 INSERT INTO `wp_term_taxonomy`( `term_id`, `taxonomy`, `description`, `parent`, `count`) select a.term_id,'post_tag', '', 0, 1 from wp_terms a left join wp_term_taxonomy b on a.term_id=b.term_id where a.name='孩子' and b.term_id is null ; -- 插入标签对应的文章(所有文章中或标题中含有该词的均添加) INSERT INTO `wp_term_relationships`(`object_id`, `term_taxonomy_id`, `term_order` ) select cc.ID,aa.term_taxonomy_id, 0 from wp_term_taxonomy aa inner join wp_terms bb on aa.term_id=bb.term_id inner join ( select a.ID from wp_posts a inner join wp_term_relationships b on a.ID=b.object_id inner join wp_term_taxonomy c on b.term_taxonomy_id=c.term_taxonomy_id where c.taxonomy='category' and a.post_status='publish' and ( a.post_title like '%孩子%' or a.post_content like '%孩子%' ) ) cc on 1=1 left join wp_term_relationships dd on dd.object_id=cc.id and dd.term_taxonomy_id=aa.term_taxonomy_id where bb.name='孩子' and dd.object_id is null ;   -- 最后一步,更新标签对应多少文章 update wp_term_taxonomy a inner join (select term_taxonomy_id,count(*) sl from wp_term_relationships group by term_taxonomy_id ) b on a.term_taxonomy_id=b.term_taxonomy_id set a.count=b.sl 需要完整的简单易操作的 excel 导入版的,请关注站长微信公众号 “番禺小学”回复 "wordpress导入标签" 获取。