I'd like to use wp_insert_category() to create a category that's displayed as "My Category" but has a category slug of "test-my-category".
Can I d开发者_如何学Goo this with wp_insert_category? Anyone have an example?
$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
)
);
See http://codex.wordpress.org/Function_Reference/wp_insert_term
Initial Taxonomies include: 'category', 'post_tag', 'nav_menu', 'link_category' (defined in wp-includes/taxonomy.php)
Yes you can. Do the following:
$category = array('cat_name'=>'My Category', 'category_nicename'=>'test-my-category');
wp_insert_category($category);
cat_name is used for the title of the category whilst category_nicename is used for the slug.
Function Reference:wp insert category « WordPress Codex
精彩评论