custom post types – Create loop from selected terms in ACF taxonomy field

Question

This feels like an easy question but I just cannot get it to work.

I have a basic custom post loop displaying posts based on a taxonomy of location and can then manually change the terms to show posts tagged with the same term. All works fine.

What I am trying to do is change the manual term selection for an ACF taxonomy field called ‘case_study_location’, so what ever term is selected there then shows the correct posts in my loop. I have tried many different things but cannot get it to work.

Here is my loop

<?php 

$loop = new WP_Query( array( 
                'post_type' => 'case_studies', 
                'posts_per_page' => 3, 
                'post_status' => 'publish',
                'tax_query' => array(
array(
'taxonomy' => 'location',
'field' => 'slug',
'terms' => 'location-two'
)
) ) ); ?>
                
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

                        <h3><?php the_title(); ?></h3>
                        <?php the_terms( $post->ID, 'location', 'categories: ', "https://wordpress.stackexchange.com/" ); ?>

            <?php endwhile; wp_reset_query(); ?>

0
user1961395 1 month 2021-10-19T10:07:48-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse