WP_Taxonomy object not setting hierarchical for custom taxonomies

I am trying to get all registered taxonomies which are hierarchically true (e.g. category). When I am retrieving all taxonomies using get_taxonomies() function it is returning all taxonomies correctly but the hierarchical => set always null (under [rewrite] for custom taxonomies. Please have the reference codes below.

Register Taxonomy

// register taxanomy

function register_cpt_taxonomy() {

$plural = ‘Product Groups’;
$singular = ‘Product Group’;

$labels = [
‘name’ => esc_html__( $plural, ‘textdomain’ ),
‘singular_name’ => esc_html__( $singular, ‘textdomain’ ),
‘search_items’ => esc_html__( “Search Types”, ‘textdomain’ ),
‘all_items’ => esc_html__( “All {$plural}”, ‘textdomain’ ),
‘parent_item’ => esc_html__( “Parent {$singular}”, ‘textdomain’ ),
‘parent_item_colon’ => esc_html__( “Parent {$singular}:”, ‘textdomain’ ),
‘edit_item’ => esc_html__( “Edit {$singular}”, ‘textdomain’ ),
‘update_item’ => esc_html__( “Update {$singular}”, ‘textdomain’ ),
‘add_new_item’ => esc_html__( “Make {$singular}”, ‘textdomain’ ),
‘new_item_name’ => esc_html__( “New {$singular} Name”, ‘textdomain’ ),
‘menu_name’ => esc_html__( $plural, ‘textdomain’ ),
];

$args = [
‘labels’ => $labels,
‘description’ => esc_html__( ‘Add Item’, ‘textdomain’ ),
‘public’ => true,
‘hierarchical’ => true,
‘show_ui’ => true,
‘show_in_nav_menus’ => false,
‘show_tagcloud’ => false,
‘show_in_rest’ => true,
‘show_admin_column’ => true,
‘rewrite’ => [ ‘slug’ => ‘product-group’ ],

];

register_taxonomy( ‘product_group’, ‘my_cpt’, $args );

}

add_action(‘init’, ‘register_cpt_taxonomy’);

Getting Taxonomies

// get all registered taxonomies
$taxonomies = get_taxonomies( $args, ‘objects’ );

// debugging
var_dump($taxonomies);

Debug Output

// debug output
Array
(
[category] => WP_Taxonomy Object
(
[name] => category
[label] => Categories
[labels] => stdClass Object
(
[name] => Categories
[singular_name] => Category
[search_items] => Search Categories
[popular_items] =>
[all_items] => All Categories
[parent_item] => Parent Category
[parent_item_colon] => Parent Category:
[edit_item] => Edit Category
[view_item] => View Category
[update_item] => Update Category
[add_new_item] => Add New Category
[new_item_name] => New Category Name
[separate_items_with_commas] =>
[add_or_remove_items] =>
[choose_from_most_used] =>
[not_found] => No categories found.
[no_terms] => No categories
[items_list_navigation] => Categories list navigation
[items_list] => Categories list
[most_used] => Most Used
[back_to_items] => ← Back to Categories
[menu_name] => Categories
[name_admin_bar] => category
)

[description] =>
[public] => 1
[publicly_queryable] => 1
[hierarchical] => 1
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] => 1
[show_tagcloud] => 1
[show_in_quick_edit] => 1
[show_admin_column] => 1
[meta_box_cb] => post_categories_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_checkboxes
[object_type] => Array
(
[0] => post
)

[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => edit_categories
[delete_terms] => delete_categories
[assign_terms] => assign_categories
)

[rewrite] => Array
(
[with_front] => 1
[hierarchical] => 1
[ep_mask] => 512
[slug] => category
)

[query_var] => category_name
[update_count_callback] =>
[show_in_rest] => 1
[rest_base] => categories
[rest_controller_class] => WP_REST_Terms_Controller
[_builtin] => 1
)

[post_tag] => WP_Taxonomy Object
(
[name] => post_tag
[label] => Tags
[labels] => stdClass Object
(
[name] => Tags
[singular_name] => Tag
[search_items] => Search Tags
[popular_items] => Popular Tags
[all_items] => All Tags
[parent_item] =>
[parent_item_colon] =>
[edit_item] => Edit Tag
[view_item] => View Tag
[update_item] => Update Tag
[add_new_item] => Add New Tag
[new_item_name] => New Tag Name
[separate_items_with_commas] => Separate tags with commas
[add_or_remove_items] => Add or remove tags
[choose_from_most_used] => Choose from the most used tags
[not_found] => No tags found.
[no_terms] => No tags
[items_list_navigation] => Tags list navigation
[items_list] => Tags list
[most_used] => Most Used
[back_to_items] => ← Back to Tags
[menu_name] => Tags
[name_admin_bar] => post_tag
)

[description] =>
[public] => 1
[publicly_queryable] => 1
[hierarchical] =>
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] => 1
[show_tagcloud] => 1
[show_in_quick_edit] => 1
[show_admin_column] => 1
[meta_box_cb] => post_tags_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_input
[object_type] => Array
(
[0] => post
)

[cap] => stdClass Object
(
[manage_terms] => manage_post_tags
[edit_terms] => edit_post_tags
[delete_terms] => delete_post_tags
[assign_terms] => assign_post_tags
)

[rewrite] => Array
(
[with_front] => 1
[hierarchical] =>
[ep_mask] => 1024
[slug] => tag
)

[query_var] => tag
[update_count_callback] =>
[show_in_rest] => 1
[rest_base] => tags
[rest_controller_class] => WP_REST_Terms_Controller
[_builtin] => 1
)

[nav_menu] => WP_Taxonomy Object
(
[name] => nav_menu
[label] => Navigation Menus
[labels] => stdClass Object
(
[name] => Navigation Menus
[singular_name] => Navigation Menu
[search_items] => Search Tags
[popular_items] => Popular Tags
[all_items] => Navigation Menus
[parent_item] =>
[parent_item_colon] =>
[edit_item] => Edit Tag
[view_item] => View Tag
[update_item] => Update Tag
[add_new_item] => Add New Tag
[new_item_name] => New Tag Name
[separate_items_with_commas] => Separate tags with commas
[add_or_remove_items] => Add or remove tags
[choose_from_most_used] => Choose from the most used tags
[not_found] => No tags found.
[no_terms] => No tags
[items_list_navigation] => Tags list navigation
[items_list] => Tags list
[most_used] => Most Used
[back_to_items] => ← Back to Tags
[menu_name] => Navigation Menus
[name_admin_bar] => Navigation Menu
[archives] => Navigation Menus
)

[description] =>
[public] =>
[publicly_queryable] =>
[hierarchical] =>
[show_ui] =>
[show_in_menu] =>
[show_in_nav_menus] =>
[show_tagcloud] =>
[show_in_quick_edit] =>
[show_admin_column] =>
[meta_box_cb] => post_tags_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_input
[object_type] => Array
(
[0] => nav_menu_item
)

[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => manage_categories
[delete_terms] => manage_categories
[assign_terms] => edit_posts
)

[rewrite] =>
[query_var] =>
[update_count_callback] =>
[show_in_rest] =>
[rest_base] =>
[rest_controller_class] =>
[_builtin] => 1
)

[link_category] => WP_Taxonomy Object
(
[name] => link_category
[label] => Link Categories
[labels] => stdClass Object
(
[name] => Link Categories
[singular_name] => Link Category
[search_items] => Search Link Categories
[popular_items] =>
[all_items] => All Link Categories
[parent_item] =>
[parent_item_colon] =>
[edit_item] => Edit Link Category
[view_item] => View Tag
[update_item] => Update Link Category
[add_new_item] => Add New Link Category
[new_item_name] => New Link Category Name
[separate_items_with_commas] =>
[add_or_remove_items] =>
[choose_from_most_used] =>
[not_found] => No tags found.
[no_terms] => No tags
[items_list_navigation] => Tags list navigation
[items_list] => Tags list
[most_used] => Most Used
[back_to_items] => ← Back to Link Categories
[menu_name] => Link Categories
[name_admin_bar] => Link Category
[archives] => All Link Categories
)

[description] =>
[public] =>
[publicly_queryable] =>
[hierarchical] =>
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] =>
[show_tagcloud] => 1
[show_in_quick_edit] => 1
[show_admin_column] =>
[meta_box_cb] => post_tags_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_input
[object_type] => Array
(
[0] => link
)

[cap] => stdClass Object
(
[manage_terms] => manage_links
[edit_terms] => manage_links
[delete_terms] => manage_links
[assign_terms] => manage_links
)

[rewrite] =>
[query_var] =>
[update_count_callback] =>
[show_in_rest] =>
[rest_base] =>
[rest_controller_class] =>
[_builtin] => 1
)

[post_format] => WP_Taxonomy Object
(
[name] => post_format
[label] => Formats
[labels] => stdClass Object
(
[name] => Formats
[singular_name] => Format
[search_items] => Search Tags
[popular_items] => Popular Tags
[all_items] => Formats
[parent_item] =>
[parent_item_colon] =>
[edit_item] => Edit Tag
[view_item] => View Tag
[update_item] => Update Tag
[add_new_item] => Add New Tag
[new_item_name] => New Tag Name
[separate_items_with_commas] => Separate tags with commas
[add_or_remove_items] => Add or remove tags
[choose_from_most_used] => Choose from the most used tags
[not_found] => No tags found.
[no_terms] => No tags
[items_list_navigation] => Tags list navigation
[items_list] => Tags list
[most_used] => Most Used
[back_to_items] => ← Back to Tags
[menu_name] => Formats
[name_admin_bar] => Format
[archives] => Formats
)

[description] =>
[public] => 1
[publicly_queryable] => 1
[hierarchical] =>
[show_ui] =>
[show_in_menu] =>
[show_in_nav_menus] => 1
[show_tagcloud] =>
[show_in_quick_edit] =>
[show_admin_column] =>
[meta_box_cb] => post_tags_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_input
[object_type] => Array
(
[0] => post
)

[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => manage_categories
[delete_terms] => manage_categories
[assign_terms] => edit_posts
)

[rewrite] => Array
(
[with_front] => 1
[hierarchical] =>
[ep_mask] => 0
[slug] => type
)

[query_var] => post_format
[update_count_callback] =>
[show_in_rest] =>
[rest_base] =>
[rest_controller_class] =>
[_builtin] => 1
)

[product_group] => WP_Taxonomy Object
(
[name] => product_group
[label] => Product Groups
[labels] => stdClass Object
(
[name] => Product Groups
[singular_name] => Product Group
[search_items] => Search Types
[popular_items] =>
[all_items] => All Product Groups
[parent_item] => Parent Product Group
[parent_item_colon] => Parent Product Group:
[edit_item] => Edit Product Group
[view_item] => View Category
[update_item] => Update Product Group
[add_new_item] => Make Product Group
[new_item_name] => New Product Group Name
[separate_items_with_commas] =>
[add_or_remove_items] =>
[choose_from_most_used] =>
[not_found] => No categories found.
[no_terms] => No categories
[items_list_navigation] => Categories list navigation
[items_list] => Categories list
[most_used] => Most Used
[back_to_items] => ← Back to Categories
[menu_name] => Product Groups
[name_admin_bar] => Product Group
[archives] => All Product Groups
)

[description] => Add product groups
[public] => 1
[publicly_queryable] => 1
[hierarchical] => 1
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] =>
[show_tagcloud] =>
[show_in_quick_edit] => 1
[show_admin_column] => 1
[meta_box_cb] => post_categories_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_checkboxes
[object_type] => Array
(
[0] => product
)

[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => manage_categories
[delete_terms] => manage_categories
[assign_terms] => edit_posts
)

[rewrite] => Array
(
[with_front] => 1
[hierarchical] =>
[ep_mask] => 0
[slug] => product-group
)

[query_var] => product_group
[update_count_callback] =>
[show_in_rest] => 1
[rest_base] =>
[rest_controller_class] =>
[_builtin] =>
)

[job_type] => WP_Taxonomy Object
(
[name] => job_type
[label] => Types
[labels] => stdClass Object
(
[name] => Types
[singular_name] => Type
[search_items] => Search Types
[popular_items] => Popular Types
[all_items] => Types
[parent_item] => Parent Type
[parent_item_colon] => Parent Type:
[edit_item] => Edit Type
[view_item] => View Type
[update_item] => Update Type
[add_new_item] => Add New Type
[new_item_name] => New Type Name
[separate_items_with_commas] => Separate Types with commas
[add_or_remove_items] => Add or remove Types
[choose_from_most_used] => Choose from most used Types
[not_found] => No Types Found
[no_terms] => No categories
[items_list_navigation] => Categories list navigation
[items_list] => Categories list
[most_used] => Most Used
[back_to_items] => ← Back to Categories
[menu_name] => Types
[name_admin_bar] => Type
[archives] => Types
)

[description] =>
[public] => 1
[publicly_queryable] => 1
[hierarchical] => 1
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] => 1
[show_tagcloud] => 1
[show_in_quick_edit] => 1
[show_admin_column] =>
[meta_box_cb] => post_categories_meta_box
[meta_box_sanitize_cb] => taxonomy_meta_box_sanitize_cb_checkboxes
[object_type] => Array
(
[0] => job
)

[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => manage_categories
[delete_terms] => manage_categories
[assign_terms] => edit_posts
)

[rewrite] => Array
(
[with_front] =>
[hierarchical] =>
[ep_mask] => 0
[slug] => job_type
)

[query_var] => job_type
[update_count_callback] =>
[show_in_rest] =>
[rest_base] =>
[rest_controller_class] =>
[_builtin] =>
[show_tag_cloud] => 1
[sort] =>
)

)

You can see the hierarchical in product_group is null/not set same for job_type which a job plugin and it is actually like a category.

Read more here:: WP_Taxonomy object not setting hierarchical for custom taxonomies

Leave a Reply

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