Title: multiple category offset
Last modified: August 24, 2016

---

# multiple category offset

 *  Resolved [mrenrich](https://wordpress.org/support/users/mrenrich/)
 * (@mrenrich)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/)
 * is there any way to get offset query for more than one category?
 * I have first 4 posts for 6 different categories on my homepage.
 * i would like to build another section with ajax load more posts starting from
   fifth post of ALL categories.
 * please help
    ty
 * [https://wordpress.org/plugins/ajax-load-more/](https://wordpress.org/plugins/ajax-load-more/)

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

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982403)
 * Hi,
    Sorry im not sure what the issue is.
 * If you don’t specify a category then it will grab all posts.
 *  Thread Starter [mrenrich](https://wordpress.org/support/users/mrenrich/)
 * (@mrenrich)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982420)
 * i mean, if i put this ALM shortcode:
 * `[ajax_load_more post_type="post" category="football,tennis,boxe" offset="3"]`
 * **offset** works only for football category.
 * i tried also doing this:
 *     ```
       $post_ids = array();
       while (have_posts()) : the_post();
         $post_ids[] = get_the_ID();
       endwhile;
       ?>
       ```
   
 * and
 *     ```
       if($post_ids){
                //Implode the posts and set a variable to pass to our exclude param.
                $postsNotIn = implode(",", $post_ids);
             }
       	echo do_shortcode('[ajax_load_more post_type="post" exclude="'.$postsNotIn.'" button_label="load more posts"]');
       ```
   
 * it works but don’t know why main loop misses 4 posts even if i see them on homepage.
 * Please help me
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982448)
 * All offset does is skips the first ‘x’ number of posts. Are you ordering the 
   posts correctly?
 *  Thread Starter [mrenrich](https://wordpress.org/support/users/mrenrich/)
 * (@mrenrich)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982452)
 * offset works only with one category and not with an array of them.
 * i well know how offset works. the problem is:
 * if i have 3 categories. i want offset for three of them not just one.
 * how to sort it out?
 * about option two (excluding posts).
    How is it possible that loop ignores 4 posts
   I see on the homepage?
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982458)
 * You can’t offset each individual category. If you are querying 3 categories and
   offsetting 4 posts then you are only offsetting 4 posts not 12.
 * You would need to run 3 separate category queries and store the post IDs in you
   $post_id variable.
 * Then run ALM and pass $post_id like you are above.
 *  Thread Starter [mrenrich](https://wordpress.org/support/users/mrenrich/)
 * (@mrenrich)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982484)
 * do u mean something like this?
 *     ```
       <?php
       // WP_Query arguments
       $args = array (
       'cat' => '2',
       'pagination' => true,
       'posts_per_page' => '6',
       'order' => 'DESC',
       'offset' => 4,
       );
   
       $my_query = new WP_Query( $args );
   
       ?>
       <ul>
   
       <?php
       if ( $my_query->have_posts() ) {
       while ( $my_query->have_posts() ) {
       $my_query->the_post(); ?>
   
       <li>
       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       </li>
       <?php
       }
       } ?>
       </ul>
   
       <?php
       wp_reset_postdata();
       ?>
       -----
       -----
   
       <?php
       $args = array (
       'cat' => '3',
       'pagination' => true,
       'posts_per_page' => '6',
       'order' => 'DESC',
       'offset' => 4,
       );
   
       $my_query = new WP_Query( $args );
   
       ?>
       <ul>
   
       <?php
       if ( $my_query->have_posts() ) {
       while ( $my_query->have_posts() ) {
       $my_query->the_post(); ?>
   
       <li>
       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       </li>
       <?php
       }
       } ?>
       </ul>
   
       <?php
       wp_reset_postdata();
       ?>
       ```
   
 * how to put the 3 merged queries into ALM shortcode?
    thank you
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982494)
 * Something like this…
    Sorry I dont have time to actually code this for you.
 * $post_ids = array();
 * Query #1
    while…. $postIds[] = $post_ids[] = get_the_ID(); endwhile…
 * Query #2
    while…. $postIds[] = $post_ids[] = get_the_ID(); endwhile…
 * Query #3
    while…. $postIds[] = $post_ids[] = get_the_ID(); endwhile…
 *     ```
       if($post_ids){
       //Implode the posts and set a variable to pass to our exclude param.
       $postsNotIn = implode(",", $post_ids);
       }
       echo do_shortcode('[ajax_load_more post_type="post" category="category1, category2, category3" exclude="'.$postsNotIn.'" button_label="load more posts"]');
       ```
   
 *  Thread Starter [mrenrich](https://wordpress.org/support/users/mrenrich/)
 * (@mrenrich)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982528)
 * thanks for suggestion.
 * i did different queries and I merged them into one array.
 * it works perfectly now
 * 🙂
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982534)
 * Excellent news!

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

The topic ‘multiple category offset’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

## Tags

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

 * 9 replies
 * 2 participants
 * Last reply from: [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/multiple-category-offset/#post-5982534)
 * Status: resolved