0

My taxonomy

    register_taxonomy(
        'king_blog_category', 
        'king_blogs',
         array(
            "hierarchical"          => true,
            "label"                 => "King blog Category",
            "singular_label"        => "label of taxonomy",
            'update_count_callback' => '_update_post_term_count',
            'query_var'             => true,
            'rewrite'               => array(
                'slug'              => 'king_blog_category',
                'with_front'        => true
            ),
            'public'                => true,
            'show_ui'               => true,
            'show_tagcloud'         => true,
            '_builtin'              => true,
            'show_in_nav_menus'     => true
        )
    );

//Get method //1:

$taxonomy = 'king_blog_category';
$tax_terms = get_terms($taxonomy);

//2 :

$taxonomy = 'king_blog_category';
$tax_terms = get_terms($taxonomy, array('hide_empty' => 0, 'parent' =>0)); 

//Result :

array([invalid_taxonomy] => array([0] => Invalid taxonomy.))
  • 1
    What action do you register your taxonomy on and what file is that code in? – Milo Jun 15 '18 at 14:07
  • why are you setting _builtin attribute..? just curious since i don't know what it does. and you set some attributes, that are default to your values anyway, so why exactly do you set these..? – honk31 Jun 15 '18 at 14:11
1

get_terms first and only parameter should be an array. docs

get_terms([
    'taxonomy' => 'king_blog_category',
    'hide_empty' => 0,
    'parent' => 0
]);
  • Same issue raised. – rajasekar Jun 15 '18 at 13:56
  • so what do you get, when you set this anywhere in your theme? header.php for example $taxonomies = get_taxonomies();foreach ( $taxonomies as $taxonomy ) {echo '<p>' . $taxonomy . '</p>';} – honk31 Jun 15 '18 at 14:00
  • category, post_tag, nav_menu, link_category, post_format, portfolio-category, product_type, product_visibility, product_cat, product_tag, product_shipping_class. – rajasekar Jun 15 '18 at 14:18
  • But get terms() function i will get king_blog_category and also worked my register taxonomy (category) in my ustom post type. – rajasekar Jun 15 '18 at 14:20
  • @raja that means, that your taxonomy, that you mention above, is not registered at all. to quote Milo: What action do you register your taxonomy on and what file is that code in? – honk31 Jun 15 '18 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.