Title: query_posts &amp; multiple categories
Last modified: August 19, 2016

---

# query_posts & multiple categories

 *  [Raz88](https://wordpress.org/support/users/raz88/)
 * (@raz88)
 * [16 years ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/)
 * Hi, so on the home page of a website I’m currently working on I am trying to 
   display posts in that are in multiple categories on the homepage. I’m trying 
   to display posts in categories 8, 4, 3 and also display posts just in category
   6.
 * Here is my current query:
    <?php query_posts(array(‘category__and’=>array(8,4,3)));?
   >
 * It was originally:
    <?php query_posts(array(‘category__and’=>array(8,4,3)&array(
   6))); ?>
 * But that just screwed it up and displayed all categories.
 * The reason I’m trying to do this is because I on the website I’m working on [http://www.w-lbaseball.org](http://www.w-lbaseball.org)
   there are posts in categories: Announcements, Games, and Schedule. But there 
   are some posts that are only located in only ‘Games’ & ‘Schedule’, these posts
   have no content but have custom fields used to display info on the scheduling
   page and the sidebar. I don’t want them to show up on the homepage unless there
   in the category ‘Announcements’ also. The news category is a separate category
   that I want to use strictly to display any current news but not be require to
   be in any of the three other categories.
 * Any assistance with this dilemma is very much appreciated.
 * -Raz88

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [16 years ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/#post-1503263)
 * Based on the information from the [query_posts() reference document](http://codex.wordpress.org/Function_Reference/query_posts),
   it appears that your syntax should be like this:
 * `query_posts('cat=8,4,3');`
 * and
 * `query_posts('cat=6');`
 * Hope that helps.
 *  Thread Starter [Raz88](https://wordpress.org/support/users/raz88/)
 * (@raz88)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/#post-1503574)
 * Thanks for the response. I’m actually trying to get posts in categories 8, 4,&
   3 and posts from category 6 into the same loop. So for refrence sake posts that
   are in those multiples categories should appear on the front page as well as 
   posts located in that one category.
 * -Raz88
 *  [Jeremy Pry](https://wordpress.org/support/users/jpry/)
 * (@jpry)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/#post-1503587)
 * The specifics would depend on how you’re actually trying to display the content.
   If you want one loop to display all of those categories, then your code would
   be
 * `query_posts('cat=8,6,4,3');`
 * If you want separate categories on separate sections of the page, then your best
   option will be to use multiple loops instead of just one main loop.
 *  Thread Starter [Raz88](https://wordpress.org/support/users/raz88/)
 * (@raz88)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/#post-1503650)
 * As of right now the only posts that appear on the homepage of [http://www.w-lbaseball.org](http://www.w-lbaseball.org)
   are game summaries. These specific posts are in three categories: Annoucements,
   Games, and Schedule. So the loop for the main page will only allow a post that
   is part of those three categories to show up on the main page. What I want to
   do is still have the game summaries show up on the main page but I would also
   like any news or updates appear in the same loop. I would like to have any post
   that belongs to the News category to also appear in the same loop. My only problem
   is since I limit the loop to only allow posts that belong to the three categories
   I stated earlier I cannot get any posts to also appear in that same loop. I’m
   currently looking for some work around that would still allow game summaries 
   to show up as well as news updates.
 * -Raz88

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘query_posts & multiple categories’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Raz88](https://wordpress.org/support/users/raz88/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/query_posts-amp-multiple-categories/#post-1503650)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
