admin管理员组文章数量:1122846
When I try to export posts via the command line, I get an immediate error that the term is missing a parent:
$ wp export
Starting export process...
Error: Term is missing a parent: name-of-tag (123)
When I looked in Wordpress, the ID applied to a tag, which has no applicable parent/child model to it. So what is going on here and how do I fix it?
When I try to export posts via the command line, I get an immediate error that the term is missing a parent:
$ wp export
Starting export process...
Error: Term is missing a parent: name-of-tag (123)
When I looked in Wordpress, the ID applied to a tag, which has no applicable parent/child model to it. So what is going on here and how do I fix it?
Share Improve this question asked Sep 1, 2021 at 23:44 Talk Nerdy To MeTalk Nerdy To Me 2852 silver badges10 bronze badges1 Answer
Reset to default 1I recently tried to export the posts from a large WP site I inherited and faced the same issue.
For some reason, there were terms (referenced via term_id) linked to other "parent" terms inside the "wp_term_taxonomy" table and these "parent" terms simply did not exist in the "wp_terms" table.
So the simplest solution is to just set the parent to 0 for these terms inside the "wp_term_taxonomy" table.
BEFORE PROCEEDING ensure you've taken a backup of your database. I can't stress this enough...
Then identify the offending terms that have a "parent" term which does not exist:
/* For categories */
SELECT * FROM `wp_term_taxonomy` WHERE taxonomy = 'category' AND parent > 0 AND parent NOT IN(SELECT term_id FROM `wp_terms`);
/* For tags */
SELECT * FROM `wp_term_taxonomy` WHERE taxonomy = 'post_tag' AND parent > 0 AND parent NOT IN(SELECT term_id FROM `wp_terms`);
/* For custom terms */
SELECT * FROM `wp_term_taxonomy` WHERE taxonomy = 'some_custom_term' AND parent > 0 AND parent NOT IN(SELECT term_id FROM `wp_terms`);
And finally update the "wp_term_taxonomy" table accordingly and set "parent" to 0:
/* For categories */
UPDATE `wp_term_taxonomy` SET parent = 0 WHERE taxonomy = 'category' AND parent > 0 AND parent NOT IN(SELECT term_id FROM `wp_terms`);
/* For tags (we basically "flatten" all of them to a single level) */
UPDATE `wp_term_taxonomy` SET parent = 0 WHERE taxonomy = 'post_tag';
/* For custom terms */
UPDATE `wp_term_taxonomy` SET parent = 0 WHERE taxonomy = 'some_custom_term' AND parent > 0 AND parent NOT IN(SELECT term_id FROM `wp_terms`);
After that, running your wp export...
command will just work.
P.S. If you use a DB table prefix other than "wp_", you obviously need to update all the SQL queries above accordingly.
本文标签: tagswpcli error quotTerm is missing a parentquot
版权声明:本文标题:tags - wp-cli error: "Term is missing a parent" 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283117a1926862.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论