add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );
function create_topics_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
'name' => _x( 'Blog Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Blog Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search blog_tags' ),
'popular_items' => __( 'Popular blog_tags' ),
'all_items' => __( 'All blog_tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit blog_tags' ),
'update_item' => __( 'Update blog_tags' ),
'add_new_item' => __( 'Add New blog_tags' ),
'new_item_name' => __( 'New blog_tags Name' ),
'separate_items_with_commas' => __( 'Separate blog_tags with commas' ),
'add_or_remove_items' => __( 'Add or remove blog_tags' ),
'choose_from_most_used' => __( 'Choose from the most used blog_tags' ),
'menu_name' => __( 'Blog Tags' ),
);
// Now register the non-hierarchical taxonomy like tag
register_taxonomy('blog_tags','blog_tags',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'blog_tags' ),
));
}
add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );
function create_topics_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
'name' => _x( 'Blog Tags', 'taxonomy general name' ),
'singular_name' => _x( 'Blog Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search blog_tags' ),
'popular_items' => __( 'Popular blog_tags' ),
'all_items' => __( 'All blog_tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit blog_tags' ),
'update_item' => __( 'Update blog_tags' ),
'add_new_item' => __( 'Add New blog_tags' ),
'new_item_name' => __( 'New blog_tags Name' ),
'separate_items_with_commas' => __( 'Separate blog_tags with commas' ),
'add_or_remove_items' => __( 'Add or remove blog_tags' ),
'choose_from_most_used' => __( 'Choose from the most used blog_tags' ),
'menu_name' => __( 'Blog Tags' ),
);
// Now register the non-hierarchical taxonomy like tag
register_taxonomy('blog_tags','blog_tags',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'blog_tags' ),
));
}
Your second parameter to register_taxonomy
should be the post type you want the taxonomy to apply to, or an array of post types.
register_taxonomy('blog_tags','post',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'blog_tags' ),
));
Will make this taxonomy show up for the built-in post
post type.
What you need to do is specify both the custom post type you're using and the taxonomy you're registering. In your code, you used blog_tags
for both, and that won't work.
If you want to add the tag
taxonomy to a blogs
custom post type, you would do so with the following:
register_taxonomy('tag', 'blogs', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'tag' ),
));
blog_tags
custom post type? – bravokeyl Commented Sep 30, 2016 at 7:01