Title: Offset 2 categories
Last modified: August 21, 2016

---

# Offset 2 categories

 *  [DanteSantadio](https://wordpress.org/support/users/dantesantadio/)
 * (@dantesantadio)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/offset-2-categories/)
 * Hi there. I have 2 sections on my site, section one displays 2 posts. The latest
   2 post from 2 different categories(Video and News).
 * I’m calling those latest post like this:
 * `<?php if (have_posts()) : query_posts('category_name=News&showposts=1'); while(
   have_posts()) : the_post(); ?>`
 * `<?php if (have_posts()) : query_posts('category_name=Video&showposts=1'); while(
   have_posts()) : the_post(); ?>`
 * In section two I have integrated the loop from a theme. But I want that second
   loop to start at an offset of 1 for each category. So that the latest post for‘
   Video’ and the latest post for ‘News’ won’t be called by the second loop as this
   creates double blogposts on my page.
 * I can’t seem to get this working. Can someone point me in the right direction.
 * I tried `query_posts('category_name=News,Video&offset=1')` for the second loop
   but this doesn’t work.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/offset-2-categories/#post-4660001)
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 * `'category_name'` uses only **one **category _slug _as value, **not two** category
   _titles_.
 * is the section two in the same template?
 * for how to avoid duplicates, review [https://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action](https://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action)
 *  Thread Starter [DanteSantadio](https://wordpress.org/support/users/dantesantadio/)
 * (@dantesantadio)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/offset-2-categories/#post-4660087)
 * Ah! Very helpful thanks. I’ll be able to sort it out now.
    No the two sections
   are not in the same template.
 *  Thread Starter [DanteSantadio](https://wordpress.org/support/users/dantesantadio/)
 * (@dantesantadio)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/offset-2-categories/#post-4660093)
 * Okay I came along way and learned a lot. This is what I have so far:
 * For loop 1 with category 3:
 *     ```
       <?php
       			$do_not_duplicate = array ();
       			$my_query = new WP_Query( array(
       			'cat' => '3',
       			'showposts' => 1
       			));
   
       			if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
   
       	        <?php $do_not_duplicate[] = $post->ID; ?>		
   
       	        <?php endwhile; ?>
       ```
   
 * For loop 1 with category 4:
 *     ```
       <?php
       		$my_query = new WP_query( array(
       		'cat' => '4',
       		'showposts' => 1,
       		'post__not_in' => $do_not_duplicate
       		));
       		if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
   
       		<?php $do_not_duplicate[] = $post->ID; ?>	
   
       		<?php endwhile; ?>
       ```
   
 * And for the main loop with both categories:
 *     ```
       $my_query = new WP_Query( array(
       'cat' => '3,4',
       'post__not_in' => $do_not_duplicate
       ) );
   
       if ( have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post();
       <?php $do_not_duplicate[] = $post->ID; ?>
       <?php endwhile; ?>
       ```
   
 * But this is only working partially. The latest post of category 3 is still being
   duplicated in the main loop. And the second post is nowhere to be seen.
    What
   am I doing wrong?

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

The topic ‘Offset 2 categories’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [offset](https://wordpress.org/support/topic-tag/offset/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [DanteSantadio](https://wordpress.org/support/users/dantesantadio/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/offset-2-categories/#post-4660093)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
