Support

Account

Home Forums ACF PRO Get taxonomy terms from custom loop Reply To: Get taxonomy terms from custom loop

  • Thanks James.

    I’m afraid I omitted the while loop from my original example code, I am in fact using the same as yours – this:

    while( $query_clients->have_posts() ) { $query_clients->the_post();

    Here’s my full code:

    $client_args = array (
    'post_type' => array( 'clients' ),
    );
    
    $query_clients = new WP_Query( $client_args );
    
    if ( $query_clients->have_posts() ) {
    
      while ( $query_clients->have_posts() ) { 
          
        $query_clients->the_post(); ?>
    
        <h2><?php the_title(); ?></h2>
    
        <?php 
    
        // Key Tasks
        // --------------------
    
        $terms = wp_get_object_terms( $post->ID, 'key_tasks' );
    
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    
          foreach ( $terms as $term ) {
    
            echo '<p class="item-text">' .$term->name. '</p>';
    
          }
    
        }
    
        echo '<pre>';
    
          var_dump( $terms );
    
        echo '</pre>';
    
      <?php } ?>
    
    <?php } else {
    
    // no posts found
    
    }
    
    wp_reset_postdata();