Support

Account

Home Forums Front-end Issues Get Taxonomy Name in loop

Helping

Get Taxonomy Name in loop

  • For some reason, I cannot get my taxonomy field to return anything within a nested WP_Query loop. I have a field-and-discipline taxonomy field on Staff custom post types. When I bring up a Staff in a WP_Query loop, I can recall any field I want from that post, except a taxonomy field.

         $args = array(
              'post__in' => $staffID,
              'posts_per_page' => -1,
              'post_type' => 'staff'
          );
    
          $staffProfiles = new WP_Query($args);
    
          if($staffProfiles->have_posts()):
    
              while ($staffProfiles->have_posts()) : $staffProfiles->the_post();
    
                  $id = get_the_ID();
                  $staffTitle = get_field('title', $id);
                  $staffName = get_the_title();
                  $discipline = get_field('teaching_disciplines', $id);
    
                  print_r($discipline); // Returns nothing
    
              endwhile;
    
          endif;
    
          wp_reset_postdata(); 

    Not sure what I’m overlooking here. It works perfectly fine in the loop.

  • I don’t see anything in the code your provided that looks like a problem.

    Is the taxonomy field a sub field of some other field?

    What is the return value set to for the taxonomy field?

    Is it returning anyghing? try var_dump($discipline);

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

You must be logged in to reply to this topic.