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…
Thanks John
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.