Title: Posts per page missing 2 posts &#8211; Custom query
Last modified: August 20, 2016

---

# Posts per page missing 2 posts – Custom query

 *  [gashface](https://wordpress.org/support/users/gashface/)
 * (@gashface)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/)
 * I am running a custom query but when returning posts_per_page, it is always two
   behind. I am using a custom post type called events, that is pulling in the code
   to display the posts from the functions file. I also want to implement pagination,
   will this be a problem?
 * Any ideas?
 *     ```
       <?php
       	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          	//Current exhibitions
          	$args = array(
          	       'post_type' => 'exhibitions',
          	       'orderby'   => 'exhibition_start_date',
          	       'meta_key'  => 'exhibition_start_date',
          	       'order'     => 'ASC',
          	       'posts_per_page' => 6,
          	       'paged' => $paged
          	   );
   
          		$my_query = new WP_Query( $args );
   
             while ( $my_query->have_posts() ) : $my_query->the_post();
                  $exhibition_start_date = get_post_meta($post->ID, 'exhibition_start_date', true);
                  //Current
   
                  if ($exhibition_start_date >= date('Y-m-d') ) {
                      get_exhibition_container();
                  }
   
          		endwhile;
   
          wp_reset_postdata();
       ?>
       ```
   
 * I can post the custom function from my functions file if need be but it’s quite
   long
 * Would there be any reason for it consistensly missing two posts?

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086328)
 * Add `var_dump($my_query);` right after `$my_query = new WP_Query( $args );` and
   tell me if all of your posts are in there.
 *  Thread Starter [gashface](https://wordpress.org/support/users/gashface/)
 * (@gashface)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086339)
 * Nope still missing two posts?
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086343)
 * Try it without the paging stuff– the last two `$args`.
 * Also, make sure the missing posts are published, not drafts, and have the ‘exhibition_start_date’
   meta_key.
 *  Thread Starter [gashface](https://wordpress.org/support/users/gashface/)
 * (@gashface)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086346)
 * Yeah I’ve tried that before. Even when using the default amount of posts and 
   no paging (which consequently isn’t working either), it misses out two posts.
 * They all have the meta data too.
 * Is it possible the problem lies with the original functions in functions.php?
 *     ```
       function get_exhibition_container() {
           global $post;
           ?>
           <section class="exhibition_container clearfix">
   
           <?php the_post_thumbnail('slideshowad', array('class' => 'exhibition')); ?>
   
            <div class="left-column-short">
            <p> 
   
            <?php
            $custom = get_post_custom();
           	?>
   
            <strong>
            <?php echo date("F d, Y",strtotime($custom["exhibition_start_date"][0])); ?> 
   
            -<br/>
       	<?php echo date("F d, Y",strtotime($custom["exhibition_end_date"][0])); ?> 
   
            <?php echo get_post_meta($post->ID, 'exhibition_location', true); ?></strong>
   
              <br/>
             <em> <?php  if($custom["exhibition_start_time"][0]);
               echo get_post_meta($post->ID, 'exhibition_start_time', true);' 
   
               -' ?>
             <?php  if($custom["exhibition_end_time"][0]);
       		  echo get_post_meta($post->ID, 'exhibition_end_time', true); ?></em>
           </div>
            <div class="right-column-long">
       	    <div class="right-text">
       	    <h2 class="caps"><?php echo '<a href="'. get_post_permalink($post->ID) . '">'. $post->post_title .'</a></h2>' ?>
       	    <?php the_excerpt($post->ID) ?>
       	    </div>
           </div>
           </section>
       ```
   
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086372)
 * > Is it possible the problem lies with the original functions in functions.php?
 * No, not really. You aren’t getting that far. We’ve established that. I’ll try
   to revisit this later.
 *  Thread Starter [gashface](https://wordpress.org/support/users/gashface/)
 * (@gashface)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086398)
 * okay, thanks for the help! I appreciate it.
 *  Thread Starter [gashface](https://wordpress.org/support/users/gashface/)
 * (@gashface)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086525)
 * I just wondered if you’d manage to come up with any more ideas of what this could
   be?
 * Var dump – on further perusal I think it might actually be bringing through all
   posts? including past exhibitions, so those after the date (so past events) but
   this is probably because the if statement is after the dump?
 * Thanks
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086528)
 * `var_dump` just dumps the information it doesn’t change it. Put `var_dump($post);`
   before ‘$exhibition_Start_date….` and remove everything else. In other words,
   this:
 *     ```
       while ( $my_query->have_posts() ) : $my_query->the_post();
                  var_dump($post);
       endwhile;
       ```
   
 * Make sure that all of your exhibitions are there because that determines what
   we do next.

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

The topic ‘Posts per page missing 2 posts – Custom query’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/posts-per-page-missing-2-posts-custom-query/#post-3086528)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
