WordPress: How to add multiple taxonomies in custom post types


Subrata Sarkar

I created a custom post type called user-story. This $argslooks like this:

$args = array(
   'labels' => $labels,
   'hierarchical' => true,
   'description' => 'description',
   'taxonomies' => array('category', 'story-type', 'genre'),
   'show_ui' => true,
   'show_in_menu' => true,
   'menu_position' => 5,
   'menu_icon' => 'http://webmaster.webmastersuccess.netdna-cdn.com/wp-content/uploads/2015/03/pencil.png',
   'public' => true,
   'has_archive' => true,
   'query_var' => true,
   'capability_type' => 'post',
   'supports' => $supports,
   'rewrite' => $rewrite,
   'register_meta_box_cb' => 'add_story_metaboxes' );

register_post_type('user_story', $args);

The problem is here 'taxonomies' => array('category', 'story-type', 'genre'),. I can't see my categories story-typeand adding new storiesgenre in the admin page. Appears only .category

These two story-typesums genreare custom taxonomies. I deactivated the CPT plugin ( user_story) and then reactivated it. But still not exceeding custom taxonomy criteria.

Both of these custom taxonomies are registered through the plugin, and they are visible in the Admin menu. Terms registered under these taxonomies also appear in their respective listing pages.

Screenshot 1: List of terms registered in the taxonomystory-type

enter image description here

Screenshot 2: List of terms registered in the taxonomygenre

enter image description here

Screenshot 3: "Add New Story" page - none of the above taxonomies are listed other categorythan only the built-in taxonomy

enter image description here

I quoted this .

Matt Krupnick

This should help : https://codex.wordpress.org/Function_Reference/register_taxonomy

Put this code in your functions.php file and add your custom taxonomy to your custom post type.

<?php
add_action( 'init', 'create_user_story_tax' );

function create_user_story_tax() {

    /* Create Genre Taxonomy */
    $args = array(
        'label' => __( 'Genre' ),
        'rewrite' => array( 'slug' => 'genre' ),
        'hierarchical' => true,
    )

    register_taxonomy( 'genre', 'user-story', $args );

    /* Create Story Type Taxonomy */
    $args = array(
            'label' => __( 'Story Type' ),
            'rewrite' => array( 'slug' => 'story-type' ),
            'hierarchical' => true,
        )

    register_taxonomy( 'story-type', 'user-story', $args );

}
?>

Related


WordPress: How to add multiple taxonomies in custom post types

Subrata Sarkar I created a custom post type called user-story. This $argslooks like this: $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'description', 'taxonomies' => array('category', 'story-type', 'genre'), 'show

WordPress: How to add multiple taxonomies in custom post types

Subrata Sarkar I created a custom post type called user-story. This $argslooks like this: $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'description', 'taxonomies' => array('category', 'story-type', 'genre'), 'show

WordPress: How to add multiple taxonomies in custom post types

Subrata Sarkar I created a custom post type called user-story. This $argslooks like this: $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'description', 'taxonomies' => array('category', 'story-type', 'genre'), 'show

WordPress: How to add multiple taxonomies in custom post types

Subrata Sarkar I created a custom post type called user-story. This $argslooks like this: $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'description', 'taxonomies' => array('category', 'story-type', 'genre'), 'show

WordPress filters custom taxonomies for custom post types

Shorter I have two different custom post types that share the same custom taxonomy. I want the first custom post type to show all the entries in the custom taxonomy. The second custom post type has to filter out an entry and show other custom taxonomies (maybe

Custom wordpress taxonomies not working with custom post types

Jeremy Gurley I have a problem with my 2 custom wordpress taxonomies. I created a custom post type called "kurs" and for this custom post type I also created 2 custom hierarchical taxonomies. This worked fine until I wanted to add custom functionality for the

WordPress filters custom taxonomies for custom post types

Shorter I have two different custom post types that share the same custom taxonomy. I want the first custom post type to show all the entries in the custom taxonomy. The second custom post type has to filter out an entry and show other custom taxonomies (maybe

WordPress filters custom taxonomies for custom post types

Shorter I have two different custom post types that share the same custom taxonomy. I want the first custom post type to show all the entries in the custom taxonomy. The second custom post type has to filter out an entry and show other custom taxonomies (maybe

WordPress filters custom taxonomies for custom post types

Shorter I have two different custom post types that share the same custom taxonomy. I want the first custom post type to show all the entries in the custom taxonomy. The second custom post type has to filter out an entry and show other custom taxonomies (maybe

Does WordPress not recognize custom post types and taxonomies?

username I use the "Simple Custom Post Types" plugin to create new "Custom Post Types" and use the "Simple Taxonomy" plugin to create new taxonomies, but when I want to create or update a new post, wordpress doesn't ask me Show custom types or taxonomies I hav

Wordpress URL rewriting to sync custom taxonomies and post types

room This is the current URL for my custom post type and taxonomy. I've noticed that the rewrite slug for custom post types and taxonomies cannot be both "stock" and break. So I selected "Inventory Category" and "Inventory". Current URL: 类别http://localhost:300

Wordpress URL rewriting to sync custom taxonomies and post types

room This is the current URL for my custom post type and taxonomy. I've noticed that the rewrite slug for custom post types and taxonomies cannot be both "stock" and break. So I selected "Inventory Category" and "Inventory". Current URL: 类别http://localhost:300

Add Multiple Custom Post Types in Wordpress

tone I can add one custom post type (distro) in my functions.php file which is fine, but then adding a second (project) seems a bit complicated. The problem I'm having is that the url structure doesn't respond to the path mysite.com/projects/project-name (retu

Add Multiple Custom Post Types in Wordpress

tone I can add one custom post type (distro) in my functions.php file which is fine, but then adding a second (project) seems a bit complicated. The problem I'm having is that the url structure doesn't respond to the path mysite.com/projects/project-name (retu

Custom post types and taxonomies, rewritten with the same code

james This is my first attempt at using WordPress rewrite rules, so please bear with me. The problem is that all the items I add to the portfolio have multiple categories. I want to remove categories from URL when portfolio post is displayed. site.com/portfoli

Custom post types and taxonomies, rewritten with the same code

james This is my first attempt at using WordPress rewrite rules, so please bear with me. The problem is that all the items I add to the portfolio have multiple categories. I want to remove categories from URL when portfolio post is displayed. site.com/portfoli

Custom post types and taxonomies, rewritten with the same code

james This is my first attempt at using WordPress rewrite rules, so please bear with me. The problem is that all the items I add to the portfolio have multiple categories. I want to remove categories from URL when portfolio post is displayed. site.com/portfoli

Add custom tags for custom post types in WordPress

urfusion I have many custom post types and I want two of them to be related via tags. These tags are only available for these two custom post types. For example; I have two custom post types books writer I want these two post types to have custom tags that onl

Add custom tags for custom post types in WordPress

urfusion I have many custom post types and I want two of them to be related via tags. These tags are only available for these two custom post types. For example; I have two custom post types books writer I want these two post types to have custom tags that onl