admin管理员组文章数量:1390670
Simple questions - how do I delete all categories programatically?
For instance this returns a list of all categories
$args = array(
"hide_empty" => 0,
"type" => "post",
"orderby" => "name",
"order" => "ASC"
);
$types = get_categories($args);
How do I simply delete them so I can replace them with other categories?
Simple questions - how do I delete all categories programatically?
For instance this returns a list of all categories
$args = array(
"hide_empty" => 0,
"type" => "post",
"orderby" => "name",
"order" => "ASC"
);
$types = get_categories($args);
How do I simply delete them so I can replace them with other categories?
Share Improve this question edited Jun 27, 2017 at 9:08 CodeMascot 4,5372 gold badges15 silver badges25 bronze badges asked Jun 27, 2017 at 8:25 user122667user122667 32 bronze badges2 Answers
Reset to default 2Please have look on the below code block-
$args = array(
"hide_empty" => 0,
"type" => "post",
"orderby" => "name",
"order" => "ASC"
);
$types = get_categories($args);
foreach ( $types as $type) {
wp_delete_category( $type->ID );
}
The function wp_delete_category
will delete a single category. So we need to run a loop through $types
to delete each single category.
Hope that helps.
$cats = get_categories( [
'hide_empty' => 0
] );
foreach( $cats as $cat ) {
wp_delete_category( $cat->term_id );
}
本文标签: pluginsHow to delete all categories programatically
版权声明:本文标题:plugins - How to delete all categories programatically? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744701058a2620564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论