Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to show a dropdown in the option's panel for choosing a "featured product category" which is a custom taxonomy. I do this way:

register_taxonomy("Catalogs",
    array("kmproduct"),
    array("hierarchical" => true,
          "label" => "Catalogs",
          "singular_label" => "catalog",
          "rewrite" => true   ));

and in my theme_options.php i have:

...
array( "name" => "Homepage featured category",  
      "desc" => "Choose a category from which featured posts are drawn", 
      "id" => $shortname."_feat_cat",  
      "type" => "select",  
      "options" => $wp_tax,  
      "std" => "Choose a category"),

and I can't get the taxonomies list:

$args=array(   'name' => 'Catalogs');

$output = 'names'; // or objects    
$taxonomies = get_taxonomies($args,$output);

$wp_tax = array();  
foreach ($taxonomies as $category_list ) {  
     $wp_tax[$category_list->ID] = $category_list->name; 
}

array_unshift($wp_tax, "Choose a category");

What's wrong? I can't get it to work :(

share|improve this question
Are you looking for a list of terms, or a list of taxonomies? It sounds like you might have a confusion in terms (pun completely unintentional). – goldenapples Nov 2 '10 at 7:05

1 Answer

up vote 3 down vote accepted

A taxonomy is a group of terms. I think you registered a taxonomy Catalogs, and now you want to list all terms in this taxonomy. You do that with the function get_terms(), not get_taxonomies().

So your $wp_tax array should be filled like this:

$wp_tax = array(-1 => 'Choose a category');
$catalog_terms = get_terms('Catalogs');
if ($catalog_terms) {
    foreach ($catalog_terms as $catalog_term) {
        $wp_tax[$catalog_term->term_id] = $catalog_term->name;
    }
}
share|improve this answer
It works!!!! :) Thank you very much. My first try was with "$taxonomies = get_terms('theme', 'hide_empty=0');" and obviously it didn't work. – Oterox Nov 9 '10 at 15:22

protected by toscho Nov 3 '12 at 20:32

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

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