How to adjust found_posts so that it accounts for offset and pagination

You are going about this the hard way, and the less efficient way. You already have a Loop on the page. You should be able to use that and that alone.

if (have_posts()) {
  while (have_posts()) {
    the_post();
    if (6 < $wp_query->current_post) {
      // formatting for your first six posts
    } else {
      // formatting for the other posts
    }
  }
}

That’s it. No new query needed. Pagination will work with no extra effort.

Caveats:

  1. “Sticky” posts will be included in your first six posts.
  2. Your post count will be the same for all posts so on page one you
    will have six differently formatted posts plus your posts_per_page
    minus 6 other posts. Other pages will just have posts_per_page posts.

If you want an extra six on the first (front) page you will need this in your theme’s functions.php:

function special_offset_pregp_wpse_105496($qry) {
  if ($qry->is_main_query()) {
    $ppg = get_option('posts_per_page');
    $offset = 2;
    if (!$qry->is_paged()) {
      $qry->set('posts_per_page',$offset);
    } else {
      $offset = $offset + ( ($qry->query_vars['paged']-1) * $ppg );
      $qry->set('posts_per_page',$ppg);
      $qry->set('offset',$offset);
      add_filter('found_posts', 'special_offset_pregp_fp_wpse_105496', 1, 2 );
    }
  }
}
add_action('pre_get_posts','special_offset_pregp_wpse_105496');

function special_offset_pregp_fp_wpse_105496($found_posts) {
  return $found_posts - 2;
}

Leave a Comment