Support

Account

Home Forums Front-end Issues Taxonomy returns ID instead value

Solved

Taxonomy returns ID instead value

    • Juraj_

    • August 6, 2019 at 7:32 pm

    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.

    • Juraj_

    • August 8, 2019 at 9:02 pm

    Perfect! It works 😀 Thank You

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

You must be logged in to reply to this topic.

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.