0

I have a custom post type called listing and a custom taxonomy called listing_category. When I navigate to [DOMAIN]/listing/things-to-do, I would like the posts with the category of things-do-do to display only, however currently ALL posts under the listing post type are displayed. I am using the following:

$args = array( 
    'posts_per_page'        => get_option('posts_per_page'), 
    'post_type'             => 'listing',
    'tax_query'             => [
        'taxonomy'          => 'listing_category',
        'field'             => 'slug',
        'terms'             => array(81)
    ]
);

81 being the ID of the things-to-do category, though I have also tried by slug - still no joy.

Anything I'm missing here?

2
  • 1
    WordPress generates the query for you on taxonomy archives, you just need to run the default loop, why are you creating your own query?
    – Milo
    Nov 20, 2017 at 16:03
  • Because for some reason when using the default loop on its own, it returns completely the wrong number of posts (I have 79 posts, but default loop returns 50 for some reason), and also pagination stops working. Perhaps that is another issue, but I am a bit at a loss at the moment.
    – wickywills
    Nov 21, 2017 at 11:21

1 Answer 1

0
$args = array(
    'posts_per_page' => get_option('posts_per_page'),   
    'post_type' => 'listing',
    'tax_query' => array(
        array(
            'taxonomy' => 'listing_category',
            'field' => 'slug', //can be set to ID
            'terms' => array(81) 
        )
    )
);
$query = new WP_Query( $args );
1
  • Unless I'm missing something, all you have done is use the longer syntax for the array..? This doesn't work either unfortunately.
    – wickywills
    Nov 21, 2017 at 8:15

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.