Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In my custom query, every time I query for posts from a particular category using WP_Query() and the category has 10 posts for example, I seem to be missing a post. So querying for 10 posts only returns 9, querying for 11 posts only returns 10 and so on. Does anyone know why I am always missing one post in my query results?

This is the code I am using that is not working. Some of my other code tests have returned the same results.

if($carouselOnOff){?>
<div id="carouselContainer">
<h2 id="sponsorsTitle"><?php echo get_cat_name( $carouselCategory ) ?></h2>
<ul id="carousel">
    <?php $showPostsInCategory = new WP_Query(); $showPostsInCategory->query('cat='. $carouselCategory .'&showposts='. $carouselNumber .'');
    if ($showPostsInCategory->have_posts()) : while ($showPostsInCategory->have_posts()) : $showPostsInCategory->the_post();?>
        <li>
            <?php $data = get_post_meta( $post->ID, 'key', true ); ?>
            <a href="<?php  if ($data[ 'custom_link' ]) { echo $data[ 'custom_link' ];} else { the_permalink(); } ?>">
                <?php the_post_thumbnail('sponsor', array('title' => "")); ?>
            </a>
        </li>
    <?php endwhile; endif; ?>
</ul><!--end carousel-->
</div><!--end carouselContainer-->
<?php } ?>
share|improve this question
1  
Where is this happening? Homepage? All pages? Archive page? How about the code you're using to query the posts, can you put that up? –  m0r7if3r Mar 11 '12 at 16:28
    
append on homepage !... did not test it elsewhere –  menardmam Mar 11 '12 at 20:09
2  
Try changing 'cat='. $carouselCategory .'&showposts='. $carouselNumber .'' to 'cat='. $carouselCategory .'&posts_per_page='. $carouselNumber .'&offset=0'. –  m0r7if3r Mar 11 '12 at 20:12
1  
I made some edits to your question, pending approval of course. I hope you don't mind. –  DigitalSea Mar 11 '12 at 22:32
    
OUPS.... i just start from scratch... and then BANG... it append, the output was FINE all the post was there, but after going through jQuery carousel... one is missing !... have to find out why, but in the carousel NOT in the request ! –  menardmam Mar 12 '12 at 3:59
add comment

4 Answers

up vote 0 down vote accepted

It sounds like you have a filter running on that page that's adding an offset parameter to your WP_Query.

There aren't any really easy ways to search for all filters. The plugin Hikari Hooks is the simplest that I've seen. If you install and activate that plugin and view the problem page, you should be able to view any filters on request or pre_get_posts or other hooks that might be affecting your output. Then its just a matter of tracking down where they're being added and disabling them before your carousel query.

share|improve this answer
add comment

It sounds like a browser caching issue possibly. If you're on a PC try holding down Ctrl+Alt+F5 to do a hard refresh and clear all caches.

share|improve this answer
    
not a caching.. for sure !... no pc either ! –  menardmam Mar 11 '12 at 16:23
1  
Are you saying that the 10th won't show at first, or it won't ever show until an eleventh is added? IF you add an 11th post is it still only showing 10 meaning that the would be 11th post still doesn't appear? How many posts do you have set to show per page? –  Jeremy Jared Mar 11 '12 at 16:27
    
Eactly... no way to display the #10 post until #11 is creatred, but #11 dont show when created, until #12.. an so on ... –  menardmam Mar 11 '12 at 16:41
add comment

I was having this same issue, inside the query I had a number set to 1, which I then changed to zero, and presto! this is my new code:

<?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 0 ) { ?>
share|improve this answer
add comment

I was having a similar problem. I'm still not sure exactly what was causing it, but I was able to patch it by forcing a large 'posts_per_page' variable in the query and setting the offset to 0.

$the_query = new WP_Query(array('post_type' => 'items', 'offset' => '0', 'posts_per_page' => '9999'));
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.