Skip to main content
3 of 14
deleted 78 characters in body; deleted 46 characters in body; deleted 3 characters in body

Intentionally exceed max_num_pages on main query without getting 404?

I'm using a self-baked author.php template on WordPress 4.6.1. Its main loop by default gets all posts from a specific author. But in author.php 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 a 404. :( I obviously want to show the remaining 2 posts from $secondloop.

Changing anything inside the author.php template seems to be "too late", 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?