WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>
                $term_names = wp_get_post_terms($post->ID, 'location', array ( 'fields' => 'names' ) );
                echo wp_sprintf_l( '%l', $term_names );
<?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?

share|improve this question
up vote 0 down vote accepted

Should be easy enough. First, get the City.

<?php $city = get_field('city'); ?>

Then in your WP_Query, insert the taxonomy parameter:

<?php $loop = new WP_Query( array( 'post_type' => 'member', 'posts_per_page' => -1, 'location' => $city ) ); ?>

Et Vilola: you only get the Members that have the taxonomy $city.

share|improve this answer
Was thinking it was harder than that. Thanks! – user3571316 Jul 15 '14 at 18:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.