Home › Forums › Add-ons › Repeater Field › Taxonomy in repeater field shows ID
Hi all,
I have a quick question, that may seem simple for most of you.
How can I retrieve the name of a taxonomy in a repeater field?
My current code outputs just the ID and not the name… What am I doing wrong? (“explicit_component_type” is the taxonomy subfield)
<?php if(get_field('explicit_component')): ?>
<?php while (has_sub_field('explicit_component')): ?>
<div id="commitments">
<h3><?php the_sub_field('explicit_component_type'); ?></h3>
<?php the_sub_field('explicit_component_text'); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
Anyone? The way it is set-up now it only outputs a series of numbers (taxonomy ID’s)…
Any help would be greatly appreciated…
Check out the “Basic Display” section for ACF Taxonomy fields:
http://www.advancedcustomfields.com/resources/taxonomy/
<?php
$terms = get_field('explicit_component');
if( $terms ): ?>
<?php foreach( $terms as $term ): ?>
<div id="commitments">
<h3><?php echo $terms['explicit_component_type'][0] -> name; ?></h3>
<p><?php echo $terms['explicit_component_text']; ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
Thank you Istreng, this clears some of my concerns!
… But how do I do that for a taxonomy in a sub_field in the repeater?
I think you and I are trying to do the same thing.
I’ve created a taxonomy called “category” inside of my repeater “asset”, and now i’m trying to retrieve all the names selected from that taxonomy. (I’m also sorting them in ASC order…)
Example of what I’m doing:
<?php
$rows = get_field('asset');
if($rows) {
foreach($rows as $key => $row) {
$column_id[$key] = $row['id'];
}
array_multisort($column_id, SORT_ASC, $rows);
$i = 0;
foreach($rows as $row) {
$taxonomyterm="";
for($i = 0; $i < count($row['category']); $i++) {
$taxonomyterm = $taxonomyterm . $row['category'][$i] -> name . ' ';
}
echo '<div class="mix img ' . $taxonomyterm . '"><img src="' . $row['image'] . '"/><h4>' . $row['name'] . '</h4>' . $row['description'] . '<div class="overlay"><a href="' . $row['file'] . '" class="expand" download>↓</a><a class="close-verlay hidden">x</a></div></div>';
$i++;
}
}
?>
Try this:
<?php
$rows = get_field('explicit_component');
if($rows) {
$i = 0;
foreach($rows as $row) {
$taxonomyterm="";
for($i = 0; $i < count($row['explicit_component_type']); $i++) {
$taxonomyterm = $taxonomyterm . $row['explicit_component_type'][$i] -> name . ' ';
}
echo '<div id="commitments"><h3>' . $taxonomyterm . '</h3>' . $row['explicit_component_text'] . '</div>';
$i++;
}
}
?>
Thanks a lot for putting so much effort into this…
Unfortunately, it still doesn’t retrieve the name of the taxonomy…
Using the first method I can only retrive the ID, but not the name..
<?php the_sub_field('explicit_component_type'); ?></h3>
You must be logged in to reply to this topic.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 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.