Skip to main content
5 of 14
deleted 10 characters in body

Intentionally exceed max_num_pages on main query without getting 404?

In author.php, the main loop by default gets all posts from a specific author. But I've added another custom WP_Query (namely $secondloop) that gets posts of a custom post type from said author too.

posts_per_page is set to 3 on both loops, and I want to paginate both.

$secondloop has its paged parameter set to the same page as the main loop by adding "paged" => (get_query_var('paged')) ? get_query_var('paged') : 1; to my argument array when initializing my new WP_Query.

THE PROBLEM:

  • If the main loop gives me 5 posts and my $secondloop gives me 2, then calling page 2 works no problemo. It shows me the remaining two posts from the main loop and none from my $secondloop (since $secondloop->have_posts()is false, so it doesn't go inside my while loop).

  • BUT if the main loop has 2 posts and $secondloop has 5, then calling page 2 results in 404. :( I obviously want to show the remaining 2 posts from $secondloop.

Changing anything inside the author.php template doesn't help, because it seems that no PHP code in there is executed any more, once WordPress detects that max_num_pages from the main loop is exceeded.

How can I "override" that behaviour?