SOLVED: PHP Error if different types of filter elements sharing same URL param (Filter - Submit)

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.

See here

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);

See Video

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.

Hi @neosan,

Thanks for the video.

Please may I know if you are using 2 different types of filters on the home page and target page?

Regarding the %5B%5D, it’s how Chrome parsing [] symbols.

Regards,
Jenn

hello,
yes the filters are different
select in the home page and Checkboxes in the target page

@neosan ,

Thanks for confirming the setup.

If you want to try a potential fix, kindly use your purchased license email to reach us (help@bricksbuilder.io). I will send you a new version to test the fix. Please include this forum thread URL as a reference.

Regards,
Jenn

Hi guys,

We’ve fixed this in Bricks 1.11, now available as a one-click download from your dashboard.

Please let us know if you are still experiencing issues.

You can see the full changelog here: Bricks 1.11 Changelog – Bricks

Best regards,
Matej

Hello,

I’m experiencing the same issue, despite having installed version 1.11. Here’s the link to the screen recording for reference.

Hi @StefanTudor,

just to make sure what the issue is. By the issue, do you mean %5B%5D in the URL, or is there another issue that I did not see it in the video?

Because %5B%5D is just how Chrome parses [], so it’s not a bug/issue.

Let me know,
Matej

Hi @Matej,

Yes, you’re right. I thought the brackets would be removed after the update, but it’s fine, I misunderstood. The filters are working well, it was just an aesthetic detail. :grin:

Thank you!

1 Like

I have the same problem, I’m also using version 1.11, but this also happens in Safari, I don’t think it’s something related to Chrome.

Hi @xdmc,

as explained above, this is not a problem, but just how browsers show [ and ] in the URL. Safari renders it the same as Chrome, while Firefox does not.

Overall, this is how it’s supposed to work. :slight_smile:

Best regards,
Matej

Hi @Matej

I have noticed that this only happens when you use the checkbox type filter, if I change to radio, select, search it does not add this to the URL.

That’s true, nd a good observation! It’s because with “Filter - Radio”, user can only select one option, so there is no need for an array, which [] or %5B%5D is.

You can see how browsers encode different characters here: Percent-encoding - MDN Web Docs Glossary: Definitions of Web-related terms | MDN


Matej