The following is supposed to display 10 posts.

Sometimes it displays 11, sometimes 12, and sometimes the desired 10 posts. It behaves the same if I swap posts_per_page for showposts or numberposts .

Where do I need to search for the problem?

    <? wp_reset_query(); ?> 
    <?  $args = array(
        'orderby'           => 'rand',
        'posts_per_page'    => '10',
    $query_footerFavorite = new WP_Query($args);

    while ($query_footerFavorite->have_posts()) : $query_footerFavorite->the_post(); ?>

            <a href="<? the_permalink(); ?>" title="<? the_title_attribute(); ?>">
                <? the_title(); ?>

    <? endwhile; ?>
    <? wp_reset_query(); ?>                 

Edit: It seams there is a problem with the posts_per_page, see print_r($query_footerFavorite):

WP_Query Object ( [query_vars] => Array ( [orderby] => rand [posts_per_page] => 10 [error]
  • codex.wordpress.org/Class_Reference/…
    – Michael
    Commented May 31, 2012 at 15:36
  • @mrwweb thank you, 'ignore_sticky_posts' => 1 solves the problem. One thing I don't understand though is that while posts_per_page returns the number of posts that I want, numberposts returns more than I want. So does numberposts automatically include the stickies?
    – Ben
    Commented May 31, 2012 at 16:03

1 Answer 1


The expected behavior of posts_per_page is to NOT count sticky posts. This can be resolved with 'ignore_sticky_posts' => 1, but then the posts don't stick to the top of the menu. (In the trac ticket for sticky posts this issue is discussed.)

There are some workarounds like this one, but they all feel a bit hacky to me. Personally I try to just deal with the expected behavior and make sure to style the sticky post class.

showposts is deprecated since WP2.1 and numberposts seems to only be a valid parameter for get_posts(). (Although I admittedly am unsure why. There's no mention of that issue on the Codex.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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