Support

Account

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

Solved

Include Taxonomy dropdown on Options page?

  • This is probably a new feature request, but I wanted to see if there is any way to do this currently.

    I’d like to set up a dropdown list of custom taxonomies on the options page to be assigned to a specific variable. As an example, let’s say a school offered different night classes every week, and had queries listing those courses in several different locations as well as navigation links. If they were to list courses in 3 taxonomies (July 20-24, July 27-31, and Upcoming for instance) in a few different locations and the navigation, it would be useful to set that variable in one place – the options page.

    Currently, the client has to cut and paste the slug in to one field to retrieve the slug that feeds the query, then the human readable title (without dashes) into another.

    Is there a way around this? It would be nice if they could set that variable universally in one location and not run the risk of having them cut and paste.

    Thanks!

  • I’m not exactly sure what you’re looking for, but you can use a taxonomy field on an options page and then get the value from the option and use it elsewhere.

    Slightly more difficult would be to use a dynamically loaded select field. http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

  • Sorry – that was extremely unclear.

    Here is what I need: to be able to select a taxonomy on the options page and pass the name and slug for the taxonomy to other pages.

    When I use get_field as discussed on the taxonomy page:
    $term = get_field('summer_semester', 'option');

    It’s not returning $term->name or $term->slug

    So I’m assuming I need to do something different when the $term is coming from the options page.

  • I just set the wp_query loops to use ‘term_id’ and set the Options Page variables to return that, but I’d still like to know how to use the Term Object and return values like slug and name.

  • 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.

  • $terms = get_field('my_tax_field', 'option');

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Include Taxonomy dropdown on Options page?’ is closed to new replies.