Title: How to Exclude Posts While Using Showposts offset
Last modified: August 19, 2016

---

# How to Exclude Posts While Using Showposts offset

 *  Resolved [Gregg](https://wordpress.org/support/users/cinemadiving/)
 * (@cinemadiving)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/)
 * I know very little about PHP and I’ve been fumbling around with this for a while,
   but I’m stumped. Hopefully I can explain this problem clearly enough.
 * On my home page the theme displays recent posts in different formats i.e. the
   most recent two within a larger feature block, the next 4 in a smaller block 
   and the rest as a list. The original code looked like this:
 *     ```
       query_posts( 'showposts=2' );
       if (have_posts()) :
       while (have_posts()) : the_post(); $category = get_the_category();
       ```
   
 * However, I want to exclude any “news” posts in the query. Unfortunately, the 
   solution I came up with results in duplicate articles in each segment block as
   you can see on my site [http://www.cinemadiving.com](http://www.cinemadiving.com).
 * The change I made:
 *     ```
       query_posts( array(
       'showposts' => '2',
       'cat' => '-20,-18') );
       if (have_posts()) :
       while (have_posts()) : the_post(); $category = get_the_category();
       ```
   
 * I would be extremely grateful if anyone could help with this?

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153453)
 * So, you’re doing a different query before each and every section? Or what?
 * There’s nothing wrong with that code, so what’s wrong must be somewhere in your
   assumptions. For example, you’re saying that you show “the most recent two within
   a larger feature block, the next 4 in a smaller block and the rest as a list”,
   which makes me wonder why your query has showposts=2 at all. Unless I’m missing
   something.
 * If you could post your whole Loop for all these sections onto [http://wordpress.pastebin.com](http://wordpress.pastebin.com)
   and then post the link back here so we can see it, we’d be better equipped to
   help you.
 * If you’re wanting to use an offset, BTW, then the offset is going to be on the
   later queries, not on the first one.
 *  Thread Starter [Gregg](https://wordpress.org/support/users/cinemadiving/)
 * (@cinemadiving)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153504)
 * Thanks for helping out Otto42. I just pasted the code here [http://wordpress.pastebin.com/m13e97a24](http://wordpress.pastebin.com/m13e97a24).
   It’s from a free theme called Magazeen.
 * Hopefully you can make sense of it.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153537)
 * Okay. This won’t work.
 *     ```
       query_posts( array(
       'showposts=4&offset=2',
       'cat' => '-20,-18'));
       ```
   
 * That’s the wrong way to do it. Try this instead:
 *     ```
       query_posts( array(
       'showposts'=>4,
       'offset'=>2,
       'cat' => '-20,-18'));
       ```
   
 * That should get what you want. Same goes for the others following that one.
 *  Thread Starter [Gregg](https://wordpress.org/support/users/cinemadiving/)
 * (@cinemadiving)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153547)
 * You are an absolute star Otto42. That works perfectly and the site is looking
   much better … thank you so much. It’s tough trying to add functionality with 
   so little PHP experience.
 * Cheers.
 *  [codydalton](https://wordpress.org/support/users/codydalton/)
 * (@codydalton)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153732)
 * Hi Otto42, I am using the same theme but I am wanting to take out the showpost
   4 & offset 2. For some reason when I remove this code it causes the site to do
   some funky stuff. I just want my post to look like my first post. My site is 
   [http://www.feltandfitted.com](http://www.feltandfitted.com)
 * Here is the [php code](http://wordpress.pastebin.com/m3e1b0a56)
 * Cinemadiving, nice work at using the theme. What tag widget are you using. that
   is pretty sweet!

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

The topic ‘How to Exclude Posts While Using Showposts offset’ is closed to new replies.

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [home](https://wordpress.org/support/topic-tag/home/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [showposts](https://wordpress.org/support/topic-tag/showposts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [codydalton](https://wordpress.org/support/users/codydalton/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/how-to-exclude-posts-while-using-showposts-offset/#post-1153732)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
