Support » Fixing WordPress » 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?

    	$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);
               if ($exhibition_start_date >= date('Y-m-d') ) {

    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)
  • Add var_dump($my_query); right after $my_query = new WP_Query( $args ); and tell me if all of your posts are in there.

    Nope still missing two posts?

    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.

    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">
         $custom = get_post_custom();
         <?php echo date("F d, Y",strtotime($custom["exhibition_start_date"][0])); ?> 
    	<?php echo date("F d, Y",strtotime($custom["exhibition_end_date"][0])); ?> 
         <?php echo get_post_meta($post->ID, 'exhibition_location', true); ?></strong>
          <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 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) ?>

    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.

    okay, thanks for the help! I appreciate it.

    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?


    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();

    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.