Support

Account

Home Forums Add-ons Options Page Include Taxonomy dropdown on Options page? Reply To: Include Taxonomy dropdown on Options page?

  • If you return set up the taxonomy field to return term object then get_field will return an array of terms

    
    $terms = get_field('my_tax_field');
    echo '<pre>'; print_r($terms); echo '</pre>';
    

    The result of the above looks something like this

    
    Array
    (
        [0] => stdClass Object
            (
                [term_id] => 2
                [name] => test category 1
                [slug] => test-category-1
                [term_group] => 0
                [term_taxonomy_id] => 2
                [taxonomy] => category
                [description] => 
                [parent] => 0
                [count] => 1
                [object_id] => 1
                [filter] => raw
            )
    
        [1] => stdClass Object
            (
                [term_id] => 3
                [name] => test category 2
                [slug] => test-category-2
                [term_group] => 0
                [term_taxonomy_id] => 3
                [taxonomy] => category
                [description] => 
                [parent] => 0
                [count] => 1
                [object_id] => 1
                [filter] => raw
            )
    
    )
    

    You then need to loop through the terms to get the term->name and term->slug

    
    foreach ($terms as $term) {
        $name = $term->name;
        $slug = $term->slug;
    }
    

    Hope that answers your question.