I have custom taxonomies
like that
/wp-admin/edit-tags.php?taxonomy=my_cat&post_type=my_poet
I want retrieve list of taxonomies in json
add_action('init', array($this, 'json_handler'));
I tried
function json_handler(){
$categories = get_terms( 'my_cat', 'orderby=count&hide_empty=0' );
print_r($categories);
}
Outpot
WP_Error Object ( [errors:WP_Error:private] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data:WP_Error:private] => Array ( ) )
But it working for normal category
$categories = get_terms( 'category', 'orderby=count&hide_empty=0' );
print_r($categories);
Outpot
Array ( [0] => stdClass Object ( [term_id] => 1 [name] => Uncategorized [slug] => uncategorized [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => [parent] => 0 [count] => 1 ) )
Here is my_cat register_taxonomy
add_action('init', array($this, 'create_stores_nonhierarchical_taxonomy'));
function create_stores_nonhierarchical_taxonomy() {
// Labels part for the GUI
$labels = array(
'name' => _x( 'Store Categories', $this -> textdomain ),
'singular_name' => _x( 'Store Categories', $this -> textdomain ),
'search_items' => __( 'Search Store Categories',$this -> textdomain ),
'popular_items' => __( 'Popular Store Categories',$this -> textdomain ),
'all_items' => __( 'All Store Categories ',$this -> textdomain ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Store Categories',$this -> textdomain ),
'update_item' => __( 'Update Store Categories' ,$this -> textdomain),
'add_new_item' => __( 'Add New Store Categories',$this -> textdomain ),
'new_item_name' => __( 'New Store Categories Name',$this -> textdomain ),
'add_or_remove_items' => __( 'Add or remove Store Categories',$this -> textdomain ),
'choose_from_most_used' => __( 'Choose from the most used Store Categories',$this -> textdomain ),
'menu_name' => __( 'Store Categories',$this -> textdomain ),
);
// Now register the non-hierarchical taxonomy like tag
register_taxonomy('my_cat',$this->post_type,array(
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'how_in_nav_menus' => true,
'public' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'my_cat' ),
));
}
Thanks