Custom query vars filters problem with pagination

The problem is the pagination parameter in the URL:

<a href="https://wordpress.stackexchange.com/questions/298648/<?php echo (in_array($marca_term->slug, $marca_arg)) ? 
  esc_url(remove_query_arg("marca')) : esc_url(add_query_arg('marca', 
  "$marca_term->slug")); ?>">

Here we see that the marca term is being added and removed, but the pagination parameter isn’t, but that’s a part of the URL not a parameter

Instead, why not use the taxonomy archives and get_term_link? Then redirect if the marca parameter is present?

  • You could eliminate the pre_get_posts changes
  • the query var would no longer be necessary
  • the pagination issue would disappear
  • You can use taxonomy-brands.php in your theme
  • You already have archives for this at example.com/brands/*term_name* just waiting for a custom template

They’re already on your site, sitting there unused. Why rebuild something that’s already there? If you’re not keen on the URL you can change it in your taxonomy registration code via the rewrite option