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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
π Weβre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.