Support

Account

Home Forums Front-end Issues Taxonomy returns ID instead value

Solved

Taxonomy returns ID instead value

  • Hi,
    first, thanks a lot for this awesome plugin!
    I have taxonomy “tags” as checkboxes displayed in admin for custom post type and want to display value – name.

    This should display name of checked taxonomies, but returns nothing:

    <?php
    $tags = get_field('projekt-tagy');
    
    if ( $tags ): ?>
    
    	<ul class="nav">
    
    		<?php foreach( $tags as $tag ): ?>
    
    			<li class="nav-item mr-2 tag-item text-purple font-weight-bold"><?php echo $tag->name; ?></li>
    
    		<?php endforeach; ?>
    
    	</ul>
    
    <?php endif; ?>

    If I want to echo only variable it returns ID:

    <?php foreach( $tags as $tag ): ?>
    
    	<li class="nav-item mr-2 tag-item text-purple font-weight-bold"><?php echo $tag; ?></li>
    
    <?php endforeach; ?>
  • Hi!

    When you create a taxonomy field you can select the return value. Select term object instead of term ID.

  • Perfect! It works 😀 Thank You

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

The topic ‘Taxonomy returns ID instead value’ is closed to new replies.