I have two taxonomies: Genres and Occasions. I want to have my parameters "translated" and treated the same as my original parameters. Currently, it only responds the correct way to parameters like ?tax-genre= and ?tax-occasion=.
I use this function to translate the parameters:
public function translate_taxonomy_params() { $translated = []; if (isset($_REQUEST['genre'])) { if (is_array($_REQUEST['genre'])) { $translated['tax-genre'] = $_REQUEST['genre']; } else { $translated['tax-genre'] = [$_REQUEST['genre']]; } unset($_REQUEST['genre']); } if (isset($_REQUEST['occasion'])) { if (is_array($_REQUEST['occasion'])) { $translated['tax-occasion'] = $_REQUEST['occasion']; } else { $translated['tax-occasion'] = [$_REQUEST['occasion']]; } unset($_REQUEST['occasion']); } return array_merge($_REQUEST, $translated); }
While this works for retrieving the correct posts on archive pages, it does not set the right checkboxes in the filter sidebar, despite my tax query being set correctly:
[tax_query] => Array ( [0] => Array ( [taxonomy] => genre [field] => slug [terms] => Array ( [0] => thriller ) ) )
My question is, how can I make the URL parameters behave the same way as the original parameters? Specifically, how can ?genre=thriller be interpreted in the backend as ?tax-genre=thriller, on every page/function?
I'm using AJAX to filter results and dynamically updating the URL with jQuery so that if a visitor opens a post, they can easily return to their previous filtered results. However, the prefix "tax-" feels less user-friendly.
Any help or suggestions would be greatly appreciated!