WordPress.org

Ready to get started?Download WordPress

Forums

Doing an AND query for categories (4 posts)

  1. Cailean
    Member
    Posted 6 years ago #

    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.

  2. MichaelH
    Member
    Posted 6 years ago #

    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));

  3. webmatter
    Member
    Posted 5 years ago #

    Many thanks, just what I was looking for!

  4. piukat
    Member
    Posted 5 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic