Hello,
during a demo test on the feasibility of a modern real estate site.
During my initial tests, I created a basic filter on the home page with 3 select taxonomies and a “Filter - Submit” button.
However, I encountered a fatal error.
While reproducing the issue to identify the culprit, I noticed the URL contained %5B%5D between the URL parameter and the = sign. This seems to affect the filter,
which the “Filter - Submit” button cannot reproduce.
To confirm this, I used a custom-made snippet to redirect the taxonomies to the filter page and filter the results. This approach worked, indicating that the problem lies with the submit button.
/**
* This code snippet modifies term links for various property-related taxonomies.
* It redirects these links to a custom archive page with prefilters applied based on the term slug.
* The taxonomies handled include property status, category, type, feature, and city.
*/
// Add a filter to modify term links
add_filter('term_link', function ($termlink, $term, $taxonomy) {
// Define the base URL for the custom term links
$base_url = trailingslashit(get_home_url()) . 'filters/?';
// Check the taxonomy and modify the term link accordingly
if ('property-status' == $taxonomy) {
// If the taxonomy is 'property-status', append the status parameter to the base URL
$termlink = $base_url . '_status%5B%5D=' . $term->slug;
} elseif ('property-category' == $taxonomy) {
// If the taxonomy is 'property-category', append the category parameter to the base URL
$termlink = $base_url . '_category%5B%5D=' . $term->slug;
} elseif ('property-type' == $taxonomy) {
// If the taxonomy is 'property-type', append the type parameter to the base URL
$termlink = $base_url . '_type%5B%5D=' . $term->slug;
} elseif ('property-feature' == $taxonomy) {
// If the taxonomy is 'property-feature', append the feature parameter to the base URL
$termlink = $base_url . '_feature%5B%5D=' . $term->slug;
} elseif ('property-city' == $taxonomy) {
// If the taxonomy is 'property-city', append the city parameter to the base URL
$termlink = $base_url . '_city%5B%5D=' . $term->slug;
}
// Return the modified term link
return $termlink;
}, 10, 3);
I’m unsure if the %5B%5D is crucial for the URL, but I hope it can be removed to maintain a clean and understandable URL structure.