Support

Account

Home Forums Front-end Issues Displaying fields from selected custom taxonomy terms

Solved

Displaying fields from selected custom taxonomy terms

  • In my WordPress posts, I’ve created a field that allows for multi-select of terms from a custom taxonomy “movies”. Each movie term has several custom fields added to enter URLs, such as “movie_website”, “trailer_url”, and so on.

    While I’ve been able to display the term objects, I’m not exactly sure how I’m able to fetch the URL fields of the selected terms?

    Currently, I’m only able to display the object and don’t know how I can make use of e.g. the $term->ID to get the field values from these terms.

    
    <?php 
    $terms = get_field('multiselect_movies');
    
    if( $terms ): ?>
      <?php foreach( $terms as $term ): ?>
    
        <div>
          <?php echo $term->ID; ?>
        </div>
    
      <?php endforeach; ?>
    <?php endif; ?>
    

    I’ve done several hours of googling before coming here so I apologize if the answer was already out there, and simply that I didn’t quite understand it.

  • After a fresh night of sleep, I think I finally got it!

    I did notice I had a typo (should be $term->term_id) in the example above, but I only wrote that as an example so it wasn’t the actual code that I ran.

    Regardless, it was really simple once I found out about “Display a value from a specific post“. I didn’t expect it working for terms as well so I disregarded it at first.

    
    <?php 
    $terms = get_field('multiselect_movies');
    
    if( $terms ): ?>
        <?php foreach( $terms as $term ): ?>
    
            <?php 
    
            $term_id = $term->term_id;
    
            $movie_id = "movie_" . $term_id;
    
            the_field('movie_website', $movie_id);
    
            ?>
    
        <?php endforeach; ?>
    <?php endif; ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Displaying fields from selected custom taxonomy terms’ is closed to new replies.