Home › Forums › General Issues › Values from a taxonomy term as a sub-field
I’ve tried everything I can come up with, but am stumped. I’m sure my code snippet here is not even close, but I’d appreciate any help I can get.
I have a repeater field called area_notes with a taxonomy sub-field called select_area. I have it set to return a term object and when I run a printr on that field I see the arrays (reproduced below). Basically I just want to be able to check the value of the slug term, and if it matches a variable that I’ll create, have it display a line of text. But I cna’t for the life of me figure out how to get the term. I’ve tried this – is it even close?
<?php if(get_field('area_notes', 'option' )): ?>
<?php while(has_sub_field('area_notes', 'option')): ?>
<?php $terms = get_sub_field('select_area'); ?>
<?php foreach ($terms as $term){ ?>
<h2><?php echo $term->slug; ?></h2>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>
This is the array that the field is creating:
Array
(
[0] => Array
(
[select_area] => stdClass Object
(
[term_id] => 32
[name] => Aurora
[slug] => aurora
[term_group] => 0
[term_taxonomy_id] => 33
[taxonomy] => area
[description] =>
[parent] => 0
[count] => 3
[object_id] => 1556
[filter] => raw
)
[area_note] => Buses not running the weeks of July 28th and August 5th
)
[1] => Array
(
[select_area] => stdClass Object
(
[term_id] => 31
[name] => Markham
[slug] => markham
[term_group] => 0
[term_taxonomy_id] => 32
[taxonomy] => area
[description] =>
[parent] => 0
[count] => 6
[object_id] => 1688
[filter] => raw
)
[area_note] => This is a Brampton Note!
)
)
Interesting timing. I had this same problem… I got this to work by adding just a little tweak.
Change:
<h2><?php echo $term->slug; ?></h2>
To:
<?php echo $term[0]->slug; ?>
The topic ‘Values from a taxonomy term as a sub-field’ is closed to new replies.
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.