admin管理员组文章数量:1279175
I have a plugin that expects there to be a default "uncategorized" category with ID=1. I've inadvertantly deleted the uncategorized category. Is it possible to recreate the category as ID=1?
When I look at a default WP install, I see that the table "wp_terms" has uncategorized as the first record with id 1. It also appears that the "wp_term_relationships" and "wp_term_taxonomy" tables are in play in this regard.
How would one go about recreating this category?
I have a plugin that expects there to be a default "uncategorized" category with ID=1. I've inadvertantly deleted the uncategorized category. Is it possible to recreate the category as ID=1?
When I look at a default WP install, I see that the table "wp_terms" has uncategorized as the first record with id 1. It also appears that the "wp_term_relationships" and "wp_term_taxonomy" tables are in play in this regard.
How would one go about recreating this category?
Share Improve this question asked Dec 13, 2010 at 23:28 Scott BScott B 5,69614 gold badges94 silver badges148 bronze badges4 Answers
Reset to default 2You need 3 steps:
1.Creating a term in wp_terms with ID is 1
2.Insert a term_taxanomy into wp_term_taxonomy with term_id is 1, and taxonomy must be category
3.Insert a term_relationships into wp_term_relationships with object_id is 1 and term_taxonomy_id is 1 Run below code in PHPMYADMIN to re-create this category!
INSERT INTO wp_terms (term_id, `name`, slug) VALUES (1, 'Uncategorized', 'uncategorized');
INSERT INTO wp_term_taxonomy (term_taxonomy_id, term_id, taxonomy, parent) VALUES (1, 1, 'category', 0);
INSERT INTO wp_term_relationships (object_id, term_taxonomy_id, term_order) VALUES (1, 1, 0);
Could your plugin not use get_option('default_category')
, which returns the ID of the default category?
It's an auto incrementing integer, so you can't using WP. But you can edit the term id and its taxonomy id from the database directly.
Either recreate it directly in the database by copying another one in and editing it, OR, why not check in your plugin files? Just do a file search for the id=1 thing and see what you come up with, and then change that to your new default id #. I always find it's easier to edit plugin and php files than mucking around in the database.
本文标签: plugin developmentDefault category got deleted How to get it back as ID1
版权声明:本文标题:plugin development - Default category got deleted. How to get it back as ID=1? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741257982a2367054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论