Question

I have a custom taxonomy term of 'artists' which is the artist's last name and a custom field of 'first_name'. To create a list all all artists with both their first name and last name I am using the following code, but it is printing as two separate lists. Do I have to join tables (never done this) to accomplish this or is there another way to write it so they are all in one list?

<?php while ( have_posts() ) : the_post(); ?>
<?php 
$args = array( 'taxonomy' => 'artists' );

$terms = get_terms('artists', $args);

$count = count($terms); $i=0;
if ($count > 0) {
    $term_list = '<ul class="artist-list">';
    foreach ($terms as $term) {
        $i++;

        $termid = 'artists_' . ($term->term_id);
        $termfirst = the_field('first_name', $termid);

        $term_list .= '<li><a href="' . get_term_link( $term->slug, $term->taxonomy ) . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $termfirst . $term->name . '</a></li>';       
    }
    $term_list .= '</ul>';
    echo $term_list;
}

?><?php endwhile; // end of the loop. ?>

The two lists are shown here on the development site

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top