Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress get_terms returns empty array for custom taxonomy

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 :)

like image 403
Griva Avatar asked Jun 30 '15 12:06

Griva


1 Answers

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.

like image 135
Griva Avatar answered Oct 17 '22 10:10

Griva