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
- Custom post type category pages pagination returns 404
- Query Multiple Post Types and Paginate Newly Created List
- A to Z List of Custom Post Type in three columns
- Custom post type, organized by categories
- What’s the WP way to load remaining custom posts?
- Custom post URL 404 error
- How do you paginate a query grouped by month?
- Single post with a Custom Post Type returns 404, when archives of the CPT work correctly
- How to handle paged param in post and custom-post-type?
- WP Query with categories only shows one post and ignores the category
- What to and how to proceed with CPT to make DB small and efficient?
- Set a CPT slug as a base name for all the taxonomies
- List all posts in a custom post type with pagination (the correct way)
- Category with post type pagination returns 404
- Post ID randomly printing on page
- A custom post within a custom post
- custom post type pagination error 404
- Display Custom Taxonomy Alphabetically
- How To Show All Custom Post Types In A Category Instead Of Pagination?
- Full Custom Post Type List Organised by two Taxonomies
- Pagination issue on category.php using custom post type query
- How to prevent a CPT’s slug and page slug from conflicting with each other?
- Displaying Custom Posts on a Page
- WordPress randomly shows 404 errors
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site
- Custom Post Type Pagination Paginates Only in URL Structure
- Get custom post type’s fields in a while loop as variables
- Is it possible to to use custom post type types on a page with the same slug somehow?
- WordPress custom post query with pagination
- Custom Post Type within the Loop on Homepage (Page Template)
- The loop seems stuck to a single (now deleted) post
- Posts per row on archive page (custom post type)
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- How do I know the ‘meta_key’ for ordering my custom post type
- Custom post type archive pagination 404
- Next Post links not working in custom post type shortcode
- Custom post type permalink tag 404
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- Hierarchical permalinks for custom post type and taxonomy
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Top Level pages in wordpress giving 404, but child pages working fine
- Custom post type conditional in loop
- Listing all term items alphabetically / sorting loop
- can these 3 queries be re-written as 1 query?