Support

Account

Home Forums Add-ons Repeater Field Taxonomy in repeater field shows ID

Solving

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>

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

The topic ‘Taxonomy in repeater field shows ID’ is closed to new replies.