The following code displays 8 posts on the 1st page. On all succeeding pages however, only 7 posts are displayed. I am assuming this is because the 1st page also displays sticky posts (whereelse the succeeding pages do not).

  • How can that problem be solved (I need 8 posts an all pages)?
  • Alternatively, the sticky posts should be displayed on all pages, not only on the first?

My original code:

$header_query = new WP_Query(

EDIT: Implementation of Daniel Sachs' suggestion:

// query db
$header_query1 = new WP_Query(
    array('post__in' => get_option('sticky_posts'), 'posts_per_page' => 1));
$header_query2 = new WP_Query(
    array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 7, 'orderby' => date, 'paged' => $page_to_load));


function getPostsFromQuery($header_query) {
    if ( $header_query->have_posts() ) : 
    // loop etc.

I am still looking for a solution that requires only one database access? And for the alternative solution with sticky posts only on page 1.

1 Answer 1


I'd suggest using two queries, one for sticky posts, another for all the others.


query_posts(array('post__in' => get_option('sticky_posts'), posts_per_page => 1));

then query all the other posts

query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), posts_per_page => 7, orderby => date, paged => '.$page_to_load.'));

this should do it.

  • I have implemented it just to try it (see original post). One needs to use WP_Query instead of query posts, and your quotes are not used correctly (with your code, pagination won't work). I would still be interested in a one-access solution?
    – Ben
    Commented Jun 18, 2011 at 8:57
  • I also still need the alternative solution for displaying sticky posts only on page 1, but having an equal amount on posts on all pages. I cannot do posts_per_page=7 on the 1st page, and then posts_per_page=8 on the next, because this breaks pagination. So what alternative is available?
    – Ben
    Commented Jun 18, 2011 at 9:09
  • I don't think you ever find a single loop solution. I don't think there is one. Commented Jun 18, 2011 at 22:05
  • BTW you don't need to use WP_Query, you also can $header_query1 = query_posts(array( ... just remember to rewind_posts(); Commented Jun 18, 2011 at 22:11
  • Aha, ok, thank you. Have you by any chance also got an idea for the alternative version with sticky posts only on page 1?
    – Ben
    Commented Jun 19, 2011 at 9:51

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.