Support

Account

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

  • Hi @juxprose

    I believe you need to use the_post() function to get make it work. Could you please try the following 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();
    
        $terms = wp_get_object_terms( $post->ID, 'key_tasks' );
    
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    
          foreach ( $terms as $term ) {
            echo '<p>' .$term->name. '</p>';
          }  
        }
    
        echo '<pre>';
    
          var_dump( $terms );
    
        echo '</pre>';
      }
    } else {
      
      // no posts found
    
    }
    
    wp_reset_postdata();

    This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/WP_Query.

    I hope this helps 🙂