[wp-trac] [WordPress Trac] #63575: Problem with posts pagination

WordPress Trac noreply at wordpress.org
Mon Jun 16 15:13:44 UTC 2025


#63575: Problem with posts pagination
--------------------------+------------------------------
 Reporter:  szymonmil111  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Permalinks    |     Version:  trunk
 Severity:  normal        |  Resolution:  duplicate
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by sandeepdahiya):

 * status:  new => closed
 * resolution:   => duplicate


Comment:

 In this case, WordPress uses two queries - 1. main query and 2. custom
 WP_Query. WordPress uses the main query to decide: which page to load
 and/or whether to show a 404 error

 If you're using custom post types (like news) and you use a separate
 WP_Query to fetch and paginate those posts—for example, setting
 posts_per_page to 5 for a total of 20 news posts—you end up with 4 pages
 in your custom query.

 However, if this query runs on a standard WordPress page that doesn’t
 normally have pagination (such as a regular "news" page created in the
 admin area), WordPress's main query is unaware of those 4 pages. So when a
 user navigates to example.com/news/page/2, WordPress checks the main query
 to see if page 2 exists. Since the main query only knows about page 1, it
 returns a 404 error—even though your custom WP_Query could technically
 fetch the correct posts for page 2.

 This has been explained better
 [https://core.trac.wordpress.org/ticket/16168#comment:2 here #16168].

 You can always modify the main query using hooks like pre_get_posts
 instead of creating a new custom query.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63575#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list