Wordpress get_terms returns empty array for custom taxonomy
Asked Answered
F

1

10

i have a bit problem with Wordpress Taxonomies... Below you can see initialization of my custom taxonomy named job_keywords.

function register_job_keywords() {

    $labels = array(
        [... lables here ...]
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'job_keywords', array( 'job' ), $args );
}

I also implement it into custom post type job.

$args = array(
    [...]
    'taxonomies'          => array( 'job_category' , 'job_keywords'),
    'hierarchical'        => false,
    [...]

In plugin init i call function register_job_keywords() which makes me see keywords in wp-admin and i can add them just like tags etc. So everything works fine in interface and i go to my php file and show all the taxonomies. So i got this :

Array
(
    [category] => category
    [post_tag] => post_tag
    [nav_menu] => nav_menu
    [link_category] => link_category
    [post_format] => post_format
    [job_category] => job_category
    [job_keywords] => job_keywords
)

As you can see job_keywords exists. But if i want to use get_terms('job_keywords') it return : Array( )

Why that so? I want to notice two things. Ones , i use print_r to see terms. Second , i already added some keywords in wp-admin interface.

Any suggestions? I hope you can help me :)

Flush answered 30/6, 2015 at 12:58 Comment(1)
I'm not sure but i suggest you to try out get the termsFingerling
F
16

Ok, i got the answer. get_terms( 'job_keywords', array("hide_empty" => false) ); get_terms have default hide_empty => true and my keywords are not used by any post.

From wordpress:

Default is true. Will not return empty terms, which means terms whose count is 0 according to the given taxonomy.

Flush answered 30/6, 2015 at 14:25 Comment(1)
thanks a bunch bhai saab. you are an angelPanegyric

© 2022 - 2024 — McMap. All rights reserved.