Not sure how well I can explain this but I will try. I have two Custom Post Types. One is "Locations" and one is "Members." I need to show only the members that belong to the location. "Locations" has an Advanced Custom Field of 'city' that would match "Members" taxonomy of 'location.' So, I want to know how I can only show posts if a term matches a field. Here is my WP_Query for "Members" that displays all "Members" separated by 'location' terms:
<?php $loop = new WP_Query( array( 'post_type' => 'member', 'posts_per_page' => -1 ) ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); $do_not_duplicate = $post->ID; ?> <?php the_post_thumbnail('thumbnail'); ?> <div class="caption"> <h4><?php the_title(); ?></h4> <h5> <?php $term_names = wp_get_post_terms($post->ID, 'location', array ( 'fields' => 'names' ) ); echo wp_sprintf_l( '%l', $term_names ); ?> </h5> </div> <?php endwhile; wp_reset_query(); wp_reset_postdata(); ?>
I also have this:
<?php $city = get_field('city'); ?>
So, what I'm asking is how do get only the posts with taxonomy 'location' term that matches '$city' to display?