tags:

views:

141

answers:

2

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 do this with wp_insert_category? Anyone have an example?

A: 

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

Rupert
A: 

$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)

George Lerner