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();
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.