Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been trying to get a drop down of my custom taxonomy terms to show up in my theme options page but with no luck. I looked a several posts here and followed the tips but the code just does not display the taxonomy terms.

/** Seasons */
$season_terms = get_terms('season');
$season_tax = array();
if( $season_terms ) {
    foreach( $season_terms as $season ) {
        $season_tax[$season->term_id] = $season->name;
    }
}

array_unshift( $season_tax, 'Choose a Season' );

I get the "Choose A Season" option and then a blank option for each of my terms ( two at the moment ). What could be causing this? I am stumped on this one???

Any help is greatly appreciated! Thanx

share|improve this question
add comment

1 Answer 1

Since you are likely developing this and you don't have any posts associated with the season taxonomy, you will not get any terms returned with get_terms('season');' unless you specify the parameterhide_emptyto be0`. I would change the code thusly:

    /** Seasons */
    $args = array( 'hide_empty' => '0' );
    $season_terms = get_terms('season', $args);
    $season_tax = array();
    if( $season_terms ) {
        foreach( $season_terms as $season ) {
            $season_tax[$season->term_id] = $season->name;
        }
    }

    array_unshift( $season_tax, 'Choose a Season' );

By default, terms are only returned if they are associated with at least one post. Check out the hide_empty parameter on this page for more information: http://codex.wordpress.org/Function_Reference/get_terms

share|improve this answer
    
Thanx, I tried that with no luck. Ended up having to move the theme-options into an included file and added it as a menu page. Now it works just fine. –  dkmojo May 17 '11 at 14:53
    
works for me. i'll have to remember that unshift trick. –  helgatheviking Aug 14 '11 at 14:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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