WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(); ?>
$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) {

        $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

share|improve this question
up vote 1 down vote accepted

Replace the_field with get_field. The former echoes data without the need to explicitly call echo on the function name, the latter returns data, which is what you need when storing data against a variable for later use in your function. In your case, concatenating the first/last name prior to its output. That should fix your list.

Although the tags have been edited (thanks toscho), in case anyone is wondering, since it's not clear in the OP, the function the_field is not to be confused with the native get_post_meta (and other) Wordpress functions that handle retrieval of post meta data. Instead this particular function and it's counterpart in get_field are part of the plugin "Advanced Custom Fields"

share|improve this answer
Thank you! Now it works as planned. – Bostow Oct 27 '12 at 19:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.