我的目标是使用某种类型的默认方法来检查Wordpress中是否存在类别,如果不存在,则添加类别.与标签相同.
这是我试图实现它的混乱:
<?php
if (is_term('football', 'category')) {
}
else (
$new_cat = array('cat_name' => 'Football', 'category_description' => 'Football Blogs', 'category_nicename' => 'category-slug', 'category_parent' => 'sports');
$my_cat_id = wp_insert_category($new_cat);
)
Run Code Online (Sandbox Code Playgroud)
我计划将其添加为插件.任何想法或帮助都会很棒!