wordpress does not see the correct custom taxonomy hierarchy

I have created custom post type – ‘portfolio’ with custom taxonomy designating the category and subcategory.

I have an example structure:
– main_category:
— subcategory_1
— subcategory_2

The problem is as following: If I check main_category and subcategory_1, WP sees correct hierarchy, but if I choose main_category and subcategory_2 to post, WP sees subcategory_2 as main_category and doesn’t see parent category. This is really strange, because this situation is only when I choose subcategory_2.
What is wrong?
My register code:

// Register Custom Post Type
function portfolio_post_type() {

$labels = array(
‘name’ => _x( ‘Portfolio’, ‘Post Type General Name’, ‘text_domain’ ),
‘singular_name’ => _x( ‘Portfolio’, ‘Post Type Singular Name’, ‘text_domain’ ),
);
$args = array(
‘label’ => __( ‘Portfolio’, ‘text_domain’ ),
‘description’ => __( ‘Portfolio’, ‘text_domain’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘thumbnail’, ‘page-attributes’ ),
‘hierarchical’ => false,
‘public’ => true,
‘has_archive’ => false,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘rewrite’ => array( ‘slug’ => ‘portfolio/%kategoria%’, ‘with_front’ => false )
);
register_post_type( ‘portfolio’, $args );

}
add_action( ‘init’, ‘portfolio_post_type’, 0 );

// Register Custom Taxonomy
function portfolio_taxonomy() {

$labels = array(
‘name’ => _x( ‘Kategorie’, ‘Taxonomy General Name’, ‘text_domain’ ),
‘singular_name’ => _x( ‘Kategoria’, ‘Taxonomy Singular Name’, ‘text_domain’ ),
‘add_new_item’ => __( ‘Dodaj nową kategorię’, ‘text_domain’ ),
);
$args = array(
‘labels’ => $labels,
‘hierarchical’ => true,
‘rewrite’ => array( ‘slug’ => ‘portfolio’, ‘with_front’ => false )
);
register_taxonomy( ‘kategoria’, array( ‘portfolio’ ), $args );

}
add_action( ‘init’, ‘portfolio_taxonomy’, 0 );

Read more here:: wordpress does not see the correct custom taxonomy hierarchy

Leave a Reply

Your email address will not be published. Required fields are marked *