Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress>;使用wp_insert_category()来分隔;类别“名称”;从类别slug或;猫名;_Php_Wordpress - Fatal编程技术网

Php WordPress>;使用wp_insert_category()来分隔;类别“名称”;从类别slug或;猫名;

Php WordPress>;使用wp_insert_category()来分隔;类别“名称”;从类别slug或;猫名;,php,wordpress,Php,Wordpress,我想使用wp_insert_category()创建一个显示为“My category”但具有“test My category”类别段塞的类别 我可以用wp_insert_category来做这件事吗?有人举个例子吗?是的,你可以。请执行以下操作: $category = array('cat_name'=>'My Category', 'category_nicename'=>'test-my-category'); wp_insert_category($category);

我想使用wp_insert_category()创建一个显示为“My category”但具有“test My category”类别段塞的类别


我可以用wp_insert_category来做这件事吗?有人举个例子吗?

是的,你可以。请执行以下操作:

$category = array('cat_name'=>'My Category', 'category_nicename'=>'test-my-category');
wp_insert_category($category);
类别名称用于类别标题,类别名称用于段塞

最初的分类法包括:“category”、“post_tag”、“nav_menu”、“link_category”(在wp includes/taxonomy.php中定义)

$parent_term = term_exists( 'fruits', 'product' ); // array is returned if taxonomy is given
$parent_term_id = $parent_term['term_id']; // get numeric term id
wp_insert_term(
  'Apple', // the term 
  'product', // the taxonomy
  array(
    'description '=> 'A yummy apple.'
    'slug' => 'apple'
    'parent'=> $parent_term_id
  )
);