Paginate_links won’t create the right links on a taxonomy filtered custom post type archive

If, for example, I click on the “2”, the page loaded as removed my
taxonomy filter(s) and paginate navigation “max-page” looks like
(seems to be) the number of pages non filtered by taxonomy

It’s not that the (taxonomy) filters are removed from the pagination links, but instead, the filters are actually never added because the form data is being submitted using the (HTTP) POST method, hence paginate_links() does not read the data (the function only parses data in the URL query string) and therefore does not add the filters into the pagination links.

And you could manually add the filters by using the add_args argument in the first (and the only) parameter for paginate_links(), but instead of having to set that argument, it’s actually simpler if you just set your form’s method to get — that way, the browser will automatically add the filters as query string in the form’s action URL and so paginate_links() will also then add the filters into the pagination links.

<form class="categorie-form" id="outingsFilterForm" role="categorie"
    action="http://thela.local:8888/eventspage" method="get"
    accept-charset="UTF-8" target="_self">

However, if the form uses the GET method, then in your outings-archive.php (post type archive) template, you’ll need to make sure the filters are read from $_GET. E.g.

// Note: Here I'm using the PHP 7's null coalescing operator (the "??" symbol).
$getTemplateVars['postedCategory'] = (array) ( $_GET['categorie'] ?? array() );
$getTemplateVars['postedCity']     = $_GET['city'] ?? '';

So apply those two changes (set the form’s method to get and use the above PHP code to read the submitted data) and check if the pagination links now includes the filters from your form.

The actual outings-archive.php is like so :

If you use the same code in a page template, then the “wp_query request” part in your code is fine.

However, on the post type archive page (e.g. the one you’ve got at /sorties), you shouldn’t be making the secondary WP_Query request because pagination will conflict with the one for the main WordPress query which runs on page load (before the archive template is loaded).

  • E.g. If your custom/secondary WordPress query had 3 (max number of) pages, yet the main query had only 2 pages, then going to page 3 would result in the error 404 (“not/nothing found”).

  • Therefore, your archive template should just display the posts in the main loop/query. I.e. Without the “wp_query request“, “$wp_query = NULL;” and “$wp_query = $temp_query;” parts..

Nonetheless, for now, just apply the two changes I said earlier above and see how things goes. 🙂