By the time you reach the template, WordPress has already queried the database and decided what to display based on those results.
You’re seeing a 404 error because based on the default main query, there are no more posts to show.
When you call query_posts
in the template, you overwrite that original query. Despite the fact that your new query results contain more posts, WordPress has no awareness of this modified query.
This is why you should never use query_posts
in the template. You’ve provided the solution to your issue already, use the pre_get_posts
action to modify the main query before it happens.
Related Posts:
- Pagination not working with custom loop
- Have different number of posts on first page
- Custom post type pagination 404 fix?
- wp_pagenavi() with custom wp_query()?
- Custom post type archive 404’s with paginate_links
- Pagination throws 404 error on custom taxonomy archive pages
- Custom Post Type Pagination Not Working On Archive Page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Archive page…limiting posts per page
- Pagination go to first page if i’m on last post
- Posts in Multiple Columns and Rows with one single loop
- Pagination throws 404
- Newer/Older posts links display same posts on every page
- Fix custom query pagination without changing site-wide posts-per-page settings
- Custom Taxonomy archive returns 404
- Pagination gives 404 error
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- How to display all posts from standard posts to custom post types in a loop with pagination?
- Paging doesn’t work?
- Help with Elementor Pagination CPT archive 404 problem
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- pagination not working for category.php (custom post types in categories)
- Custom post type pagination 404
- Pagination Error : Duplicate argument being outputted
- Custom WP_Query always respond with 200 status even when no entry
- Custom Post Type, Pagination and 404s?
- Custom post type pagination error
- Problem with custom loop navigation inside the blog page
- Custom archive page for custom taxonomy and pagination issue
- Custom post type paging return home page
- Pagination not working in custom post type. Help
- Pagination Not Working When Used With WP_Query() `offset` Property
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Pagination for custom query returns 404
- next_posts_link() always generates second page link on custom post type
- 404 error next-page [2] PageNavi custom type taxonomy
- 2 custom posts types, in their own columns, one pagination for both
- How to Fix Custom WordPress Loop with Pagination on Single Post View?
- Pagination on custom post types
- Pagination in custom post type page template
- Custom post type archive pagination with HTML5Blank theme?
- Pagination in custom loop for custom post type throwing 404 error
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- How do I paginate a custom post type listing on a custom template page?
- Fourth page of custom post type archive page does not exist
- WordPress custom post type post and category links 404
- Unable to display paging navigation with a custom post type loop
- Pagination on category pages using wp_pagenavi causes 404 errors
- WPNavi pagination links not working on custom pages
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Adding custom post type to loop
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Taxonomy posts on Archive page
- How to show related posts by category or custom post type?
- Creating a simple pagination for custom post type templates
- Get the title of custom post type in another loop
- Pass the_post() as a parameter
- How to add pagination to wp_query [duplicate]
- Show one item per category of a custom post type
- Multiple Loops On Custom Post Type Template?
- Custom Tag Description unable to display just below and outside of the Loop
- List all posts in a custom post type with pagination (the correct way)
- Category with post type pagination returns 404
- Custom Post Type within the Loop on Homepage (Page Template)
- Does WP have a global of $id?
- Bootstrap accordion looping through posts incorrectly
- Search Filter CPT, Custom Loop
- Get post content from another section in custom single page
- next page with custom post
- Custom post class, generate unique id from 1 to x depending on amount of posts?
- Create a custom taxonomy template that loops through child categories in term order?
- Why is the output of a call to the_excerpt different when the call seems to be identical?
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- Only looping through pages that have children or subpages
- creating a foreign key like relationship with custom post types
- Pagenavi Plugin and Custom Post Type – Multipage results
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Loop all post on single.php
- Enabling hierarchical in a Custom Post Type gives error 404
- Standard Page Child of CPT Not Found (404)
- custom post type single page
- Post navigation doesn’t show (in custom template, custom post type, custom query)
- Custom post types not displaying per category
- Custom Pagination based on Custom Post Type
- Pages displays correctly but returning a 404 error in http header.
- Pagination with Custom Post Type
- paging is not working properly on news archives page [duplicate]
- Custom Loop and Standard Blog Loop Issue
- 404 with Custom Post Type
- Custom loop won’t work, can’t find problem
- Loop to pull content from parent element in custom post type [duplicate]
- Problems with pagination for a custom post type
- See the process of creating a taxonomy and tell me where I made a mistake
- How to create custom page templates with default page layout framework?
- How to debug a 404 error on pages whose content is perfectly displayed when I explore it?