taxonomy tags..it is not working

admin2025-01-07  7

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' ),
      ));
}
Share Improve this question edited Sep 30, 2016 at 7:10 Andy Macaulay-Brook 3,8593 gold badges19 silver badges44 bronze badges asked Sep 30, 2016 at 6:51 Jyoti JoshiJyoti Joshi 11 bronze badge 6
  • 1 Explain what is not working. – bravokeyl Commented Sep 30, 2016 at 6:55
  • tags are not showing on wp – Jyoti Joshi Commented Sep 30, 2016 at 6:59
  • Do you have blog_tags custom post type? – bravokeyl Commented Sep 30, 2016 at 7:01
  • i solved my prb.... – Jyoti Joshi Commented Sep 30, 2016 at 7:07
  • 2 Please post it as an answer and accept it after two days. – bravokeyl Commented Sep 30, 2016 at 7:07
 |  Show 1 more comment

2 Answers 2

Reset to default 0

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' ),
));
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736261253a727.html

最新回复(0)