Sam
Sam

Reputation: 6374

Filter by multiple categories in WordPress

I would like to display only posts that are members of BOTH category 33, 39 and are post time athletes. My current code shows posts that are in category 33 AND 39 And athletes:

<?php query_posts( 'cat=33&cat=39&post_type=athletes'); ?>

What adjustments do I need to make?

Upvotes: 1

Views: 2175

Answers (1)

Jeroen
Jeroen

Reputation: 13257

You can use an array of options instead of a query string, in which you can use the category__and setting to do what you want:

<?php
query_posts(array(
    'category__and'  => array(33,39),
    'post_type'      => 'athletes'
));
?>

Upvotes: 2

Related Questions