Home › Forums › General Issues › Get taxonomy name from 'Taxonomy' field and insert into custom loop as category? › Reply To: Get taxonomy name from 'Taxonomy' field and insert into custom loop as category?
Ok I just got it working using this!
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $term_id = get_field('exercise_category') ; $args = array ( 'post_type' => 'exercise-database', 'tax_query' => array( array( 'taxonomy' => 'exercise-categories', 'terms' => array($term_id), 'operator' => 'IN' ) ), 'pagination' => true, 'paged' => $paged, 'order' => 'DESC', ); ?> <?php global $wp_query; $wp_query = new WP_Query( $args ); ?> <?php if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Looks like I needed to get the field and return as term_id. Im glad that works!
Could you let me know why you advise not to use ‘global $wp_query’. I think the reason I am using that is something to do with the CPT, but I am all ears…
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!
© 2022 Advanced Custom Fields.