Response is based on the results of the main query. The decision is made before the template is loaded, which is how WP is able to serve a 404 template in the case of a 404.
As you’ve learned, the page
post type lets you paginate endlessly in both the format pagename/page/n/
, as well as the singular pattern pagename/n/
. To generate a 404 for a different query, you’d need to hook something like template_redirect
to check if your custom query contains posts so you can force a 404 before output starts.
The preferred solution is to set the has_archive
argument for your custom post type, which enables an archive page. The main query will then be your collection of portfolio posts, and pagination will work as expected.
Related Posts:
- Custom post type archive 404’s with paginate_links
- Pagination on category page with custom post types
- send user to first page of results when reposting to page?
- Custom post type pagination 404 fix?
- Pagination throws 404 error on custom taxonomy archive pages
- Number of pages – multiple (custom) post types
- Custom permalink with pagination
- Related posts by author pagination not working on the production site
- Secondary loop pagination on custom post type single post gets redirected to first page
- Pagination Doesn’t Work
- Numeric pagination custom post type
- Pagination throws 404
- Custom wp_query pagination – next_posts_link() or wp_pagenavi() always empty
- custom post type paging not working past page 3
- Custom Taxonomy archive returns 404
- Pagination gives 404 error
- WP_Query pagination using only numbers instead of /page/1 on URL
- Pagination with custom post types results in 404 issues
- Pagination not working
- Pagination Issue: Custom Post Type In Index
- Custom query form submission pagination
- Paginated Taxonomy Term Archive including one post per term
- Unable to get paginate_links working with a custom query [duplicate]
- How to add pagination to wp_query [duplicate]
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Pagination on a custom post type loop
- Wrong request query on cpt and tax
- Previous/Next Link by Meta Value in CPT
- Pagination for Custom Taxonomy Page [duplicate]
- Pagination on with query_posts in custom post type template
- Help with Elementor Pagination CPT archive 404 problem
- Custom taxonomy rewrite give pagination 404
- Woocommerce search pagination not working
- How do you paginate a query grouped by month?
- Pagination issue on category.php using custom post type query
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- can these 3 queries be re-written as 1 query?
- pagination not working for category.php (custom post types in categories)
- Custom post type pagination 404
- Pagination doesn’t function properly for archive of a custom post type set as the front page
- Trouble with pagination
- Pagination 404 on Index with custom query
- Custom post type and custom taxonomy 404 on page 2
- How to list custom post types on a custom post type page?
- Pagination for search results of custom post type [duplicate]
- Custom Post Type Archive Pagination
- All blog posts are not showing up
- Single parent post lists child posts with pagination
- Custom post type pagination error
- Previous / Next Links For Custom Post Type Sorted By Meta_Value
- Problem with custom loop navigation inside the blog page
- custom taxonomy pagination 404 error
- Pagination in custom post type archive.php not working
- Pagination Not Working When Used With WP_Query() `offset` Property
- Numeric pagination custom post type
- How can I get custom post types to recognize pretty permalink variables?
- Problems in paginate_links with custom query loop and MB-Relationships
- WordPress doesn’t respect Page slug in custom post type url pagination. Keeps getting removed
- Make pagination work as a carousel (custom query)
- Pagination for custom query returns 404
- pre_get_posts gives 404 error on Custom Post
- 404 error next-page [2] PageNavi custom type taxonomy
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- why custom post archive gives always no more than 10 posts despite of paging settings?
- query and paginate multiple post types
- Pagination in custom loop for custom post type throwing 404 error
- Custom post type blog pagination conflict
- Custom post type pagination, single page issue
- Pagination always adding “Next” link when results come from Custom Post Type WP_query
- Paged within a custom content type template [duplicate]
- List of filtered Events is breaking paging?
- Pagination not working on homepage
- 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
- Pagination broke after updateto WordPress 3.4 [duplicate]
- WordPress custom post type post and category links 404
- Archive page – problem with pagination
- Pagination on category pages using wp_pagenavi causes 404 errors
- Meta query with boolean true/false value
- get_query_var( ‘paged’ ) not working outside of homepage
- Search multiple custom fields by using meta_query
- category__in not working on custom post type
- Date query for a custom meta field
- Set default option in dropdown of WP_Query?
- Custom WP_Query not returning results when querying custom post type
- How To Create A Custom Taxonomy 404 Page
- Problem querying Custom post type by custom fields
- cannot override post_types in WP_Query()
- Wrapping x posts in html without leaving empty html
- How to get specific post meta by title or id
- WP_Query of custom post type sorted by meta_key has unexpected results
- Display custom-post type based on the Title matching the current selected value
- WP Query filter search. Result show all posts instead just custom post type
- Display posts of a hierarchical custom post type excluding parent posts
- get_post_meta for Custom Post Type ( CPT )
- How to query posts by meta keys AND under specific category?
- How can I base a query off of the current page post type AND a meta value from another custom post type
- Custom post type navigation on static page
- Fallback if statement based on the number filtered from it
- WP Query – Can’t get posts with specific taxonomy