Support

Account

Home Forums Front-end Issues Returning Custom Field Values (including Taxonomy Terms) on Term archive pages Reply To: Returning Custom Field Values (including Taxonomy Terms) on Term archive pages

  • @hube2
    Thanks for the guidance so far. I’ve managed to solve all my problems, including the term returning concern; just one little obstacle left; might be more php/html related.

    I manage to return the custom field taxonomy terms:

    <?php 
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    
    $terms = get_field( 'custom_field', $taxonomy.'_'.$term_id);
    
    foreach( $terms as $term ):?>
    <a href="<?php echo get_term_link( $term );?>"> <?php echo $term->name; ?> </a>
    <?php endforeach; 
    ?>

    This does a good job of returning and listing the terms. It lists them down the page (separate lines). I need to list the terms separated by commas (on the same line). There are a few loop suggestions on the net about listing array entries separated by commas including the implode() function. Its proving to be a lil’ tricky incorporating a loop or the implode() function within this foreach() loop and achieving the desired output. It seems the foreach() function is forcing the values out on separate lines? Further more what about listing the terms in order of child first and parent last?

    Would appreciate your directions/suggestions.