404 on page 2 multisite

I have a a multisite installation of wordpress. On my startpage (index.php) I show posts from all the sites that belongs to the network. The problem I’m experience is that when I go to /Page/2 I get a 404 message if my main blog doesn’t have enough posts for a page 2. However on the whole network there are enough posts for 2 pages. If I add some more posts to my main blog, page 2 will be available again. My guess is that wordpress checks if any posts exists for the query before it includes index.php. I have tried to find where this could be done but have not found anything. Does anyone know if wordpress does this kind of check before index.php is included?

Solutions Collecting From Web of "404 on page 2 multisite"

Every front end page request on a WordPress site produces a main query. The template that WordPress decides to load is based on the results of that main query (you can see the order that WordPress does these things by looking at the Action Reference page). Despite the fact that you never output the results of that query, it’s still run, and in the case of paginated archives, this is an issue if you’re trying to use that pagination for a different query.

The best case scenario is to modify the main query before it’s run via the pre_get_posts action, however, this won’t work for you because you’re querying network posts, which, as far as I know, the WP_Query class can’t do on its own.

The simplest solution to this is to make your landing page a static page instead of a posts archive. Create a new page under the Pages menu in admin, then visit Settings > Reading, and under Front page displays, select A static page, then choose that page from the dropdown menu. You’ll now be able to paginate that page without it throwing a 404, because the main query will always contain just that single page’s data and won’t be potentially empty.