I have a Custom Post Type (project) and a Custom Taxonomy (project_category).
I have created a Page (Projects), which uses a custom template, in which I run a WP_Query to fetch projects and display with a pagination, using the paginate_links function.
To display the custom taxonomy archive I use a template named taxonomy-project_category.blade.php (Blade because I'm using Roots Sage).
The projects and the pagination display correctly. The pagination works well when parsing the projects list. But it displays a 404 page when clicking on the pagination links of a project_category page.
- /projects/ works, it displays the list of projects, page 1
- /projects/page/2 works, it displays the list of projects, page 2
- /project_category/category1 works, it displays the list of projects having the category1, page 1
- /project_category/category1/page/2 does NOT work, it displays a 404 page.
Here is my call to paginate_links :
paginate_links( [
'total' => $query->max_num_pages,
'current' => get_query_var( 'paged', 1 ),
'show_all' => true,
] )
Any idea why the URL /project_category/category1/page/2 is 404 instead of the taxonomy archive paginated page ?
WP_Query
has a second page, the main query that loaded the template that lives at that URL does not. Creating a custom query withWP_Query
is not how you change the results, it's a second new additional set of queries. If you want to change which posts the main query displays or change parameters then you should change it using thepre_get_posts
filter, and then all of this pagination workaround code and the bugs dissappear./projects
uses a page template, and/project_category
usestaxonomy-project_category.php
or equivalent theme template. If this is not the case please edit this info into your question so that it's clearer