WordPress.org

Support

Support » How-To and Troubleshooting » Doing an AND query for categories

Doing an AND query for categories

  • I’m trying to pull posts that belong to two categories. So if I have four categories (A, B, C, D) I want to pull only posts that are in A and B. Not to be confused with pulling all posts from A and B.

    Any help? query_posts() doesn’t seem to be able to do it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Does this example from the Codex article, query_posts(), work for you?

    query_posts(array('category__and'=>array(1,3),'showposts'=>2,'orderby'=>title,'order'=>DESC));

    Many thanks, just what I was looking for!

    I was trying to do the same. Doesn’t seem to work though. It works if I enter one category ID only. As soon as I add a second category all I get is empty space.
    I copied the exact same code, justed altered category id’s.
    What am I doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Doing an AND query for categories’ is closed to new replies.
Skip to toolbar