0

I'm trying to figure out how to list all posts that have been sorted under a specific term.

I have a custom post type named "Winemakers" under that, I have a custom taxonomy named "Wine Region". Under Wine Region, I have a city called Elgin Arizona that currently has two posts under it. How can I show all posts under Elgin Arizona?

Here's what I have so far and it throws no errors but also doesn't show anything at all. Just a blank page:

              $args = array(
                  'posts_per_page' => 100,
                  'post_status'   => 'publish',
                  'tax_query'     => array(
                      array(
                          'taxonomy'  => 'wineregion',
                          'field'     => 'id',
                          'terms'     => 75,
                          'include_children' => false
                      )
                  ),
                  'post_type'     => 'winemakers' );

              $wine_region_location = new WP_Query($args); ?>

              <?php if ( $wine_region_location->have_posts() ) : ?>
              <?php while( $wine_region_location->have_posts() ) : $wine_region_location->the_post(); ?>

                  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

              <?php endwhile; wp_reset_postdata(); ?>
1
  • maybe set 'include_children' => true?
    – Ovidiu
    Commented Jun 11, 2018 at 19:09

1 Answer 1

0

Sometimes it's easy to overthink things. I'm guilty of this with this issue. After a little frustration, I just tried to run the Wordpress loop without a new query. So just a plain jane loop and it worked fine.

So my original issue was that on my archive-winemakers.php page, I have a custom taxonomy called wineregion. I needed to list all the cities or areas that grow wine in Arizona. With these listed, the user can then click (for example Tucson Arizona) the link and he/she would be directed to my taxonomy-wineregion.php page. Then on that page, all of the vineyards or wineries in Tucson would be shown on one page.

I suspect that given that the wine region query has been triggered, and you're on the taxonomy page, that just running the loop gives you the results you need. Once in the loop, you can run the_title(), the_permalink() and everything else you would need to run in a basic loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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