add default content to custom taxonomy in wordpress -
i trying add default data set custom taxonomy called 'foods'. default data sets are;
- vegetarian
- salad
- carrot
- nonvegetarian
- chicken
- mutton
i have created taxonomy called foods, unable add default data it. please help. don't understand how use wp_insert_term() in wordpress codex.
here 2 examples in must customize theme , usage. step 1 creating term wp_insert_term(). must used hook called 'init' so:
add_action( 'init', 'your_function' ); your_function(){ $parent_term = term_exists( 'fruits', 'product' ); // array returned if taxonomy given $parent_term_id = $parent_term['term_id']; // numeric term id wp_insert_term( 'apple', // term 'product', // taxonomy array( 'description'=> 'a yummy apple.', 'slug' => 'apple', 'parent'=> $parent_term_id ) );
}
i register custom taxo's custom post type (within same file) here custom taxonomy example notes:
register_taxonomy( 'custom_tag', array('review_type'), /* if change name of register_post_type( 'custom_type', have change */ array('hierarchical' => false, /* if false, acts tags */ 'labels' => array( 'name' => __( 'custom tags', 'yourtheme' ), /* name of custom taxonomy */ 'singular_name' => __( 'custom tag', 'yourtheme' ), /* single taxonomy name */ 'search_items' => __( 'search custom tags', 'yourtheme' ), /* search title taxomony */ 'all_items' => __( 'all custom tags', 'yourtheme' ), /* title taxonomies */ 'parent_item' => __( 'parent custom tag', 'yourtheme' ), /* parent title taxonomy */ 'parent_item_colon' => __( 'parent custom tag:', 'yourtheme' ), /* parent taxonomy title */ 'edit_item' => __( 'edit custom tag', 'yourtheme' ), /* edit custom taxonomy title */ 'update_item' => __( 'update custom tag', 'yourtheme' ), /* update title taxonomy */ 'add_new_item' => __( 'add new custom tag', 'yourtheme' ), /* add new title taxonomy */ 'new_item_name' => __( 'new custom tag name', 'yourtheme' ) /* name title taxonomy */ ), 'show_admin_column' => true, 'show_ui' => true, 'query_var' => true, ) );
Comments
Post a Comment