SOLVED: Live Search Still Uses `s=` Parameter Despite Override – Need Help ASAP

Browser: Chrome 110
OS: macOS / Windows / Linux / etc.
URL: Link to a page that illustrates this issue
Video: Short screen recording that illustrates this issue (free tool: jam.dev)

[Please describe this bug in as much detail as possible so we can replicate & debug this bug]

Hello Bricks Team,

I’m facing an urgent issue with Live Search on Bricks Builder (v1.10.x). I need the search to work only on one ACF field (dranun) and completely disable the default WordPress s= parameter to avoid searching in post_title and post_content.

I’ve tried overriding the query using both pre_get_posts and bricks/query/run hooks (code below), but the s= parameter is still present in the AJAX request (s=մաշ), causing unwanted results (e.g., searching for “մաշ” returns all dermatologists because of the specialty field in post_content).

Here’s my setup:

  • Filter – Search Element: filterId="gdmwlu", targetQueryId="rmguet", filterNiceName="dranun", filterMethod="ajax", filterApplyOn="change".
  • Query Loop: rmguet, post_type="dr".
  • PHP Code:
add_action('pre_get_posts', function($query) {  
    if (defined('DOING_AJAX') && DOING_AJAX && isset($_GET['query_id']) && $_GET['query_id'] === 'rmguet') {  
        $query->set('s', '');  
        $query->set('post_type', 'dr');  
        $search_term = isset($_GET['dranun']) ? sanitize_text_field($_GET['dranun']) : '';  
        if (!empty($search_term)) {  
            $query->set('meta_query', [  
                ['key' => 'dranun', 'value' => $search_term, 'compare' => 'LIKE'],  
            ]);  
        }  
    }  
});  

add_filter('bricks/query/run', function($query, $settings, $element_id) {  
    if ($element_id === 'rmguet') {  
        $query->set('s', '');  
        $query->set('post_type', 'dr');  
        $search_term = isset($_GET['dranun']) ? sanitize_text_field($_GET['dranun']) : '';  
        if (!empty($search_term)) {  
            $query->set('meta_query', [  
                ['key' => 'dranun', 'value' => $search_term, 'compare' => 'LIKE'],  
            ]);  
        }  
    }  
    return $query;  
}, 10, 3);

Hi @mherhenry ,

I just moved this thread to “How To” category.

As you are using a very old version, we can’t directly give you a correct suggestion because the latest query filters logic is not the same as in 1.10.x

Your code will not work because in Bricks Filter AJAX endpoint, the filter values were submitted via POST request and the data was wrapped inside different array keys. (Please inspect via Dev tools)

I would suggest you use this hook to amend the posts query_vars instead.

bricks/posts/query_vars

By using this hook, with higher priority like 50, you can error_log the $query_vars to check the search value + add your custom meta_query.

Hope this helps.

Regards,
Jenn

Hi @itchycode ,

Thank you for your guidance! :blush: I’ve implemented the bricks/posts/query_vars hook as suggested and used a higher priority (999). I also checked the POST request in Dev Tools and found that the search value is sent as selectedFilters[sreabl]. My updated code now correctly retrieves the search term, but the s= parameter is still present in the AJAX response, causing unwanted results.

For example, when I search for “derm” (which is not in the dranun field), it still returns all dermatologists because of the specialty field in post_content. Here’s my updated code:

add_filter('bricks/posts/query_vars', function($query_vars, $settings, $element_id) {  
    if ($element_id === 'rmguet') {  
        $query_vars['s'] = '';  
        unset($query_vars['s']);  

        $search_term = '';  
        if (isset($_POST['selectedFilters']['sreabl'])) {  
            $search_term = sanitize_text_field($_POST['selectedFilters']['sreabl']);  
        }  

        if (!empty($search_term)) {  
            $query_vars['meta_query'] = [  
                [  
                    'key' => 'dranun',  
                    'value' => $search_term,  
                    'compare' => 'LIKE',  
                ],  
            ];  
        } else {  
            $query_vars['meta_query'] = [  
                [  
                    'key' => 'dranun',  
                    'value' => 'nonexistent_value',  
                    'compare' => 'LIKE',  
                ],  
            ];  
        }  

        $query_vars['post_type'] = 'dr';  
        error_log('Search Term: ' . $search_term);  
        error_log('Query Vars: ' . print_r($query_vars, true));  
    }  
    return $query_vars;  
}, 999, 3);  

Despite this, the s= parameter is still affecting the search. How can I completely disable s= in Live Search to ensure it only searches in the dranun field? I’d really appreciate your help! :pray:

Regards,

Mher

Hi there,

That is weird, the $query_vars still contain the “s” inside your error_log code since you already unset it?

Can you check if you have enabled “Query Bricks data in search results”

Otherwise, please provide admin credentials and all details (location of your code, actual URL of the page etc) to help@bricksbuilder.io so I can take a look.

Regards,
Jenn

Hi @itchycode ,

Thank you for your suggestion! :blush: I’ve sent an email to help@bricksbuilder.io with the details of my issue.

I wanted to share an update on my issue with Live Search in Bricks Builder. Thanks to the amazing support from the Bricks community, especially Jenn Lee, we found a solution! :blush:

The Solution:
To make Live Search work only on specific ACF fields (e.g., field_1, field_2) and avoid searching in post_title or post_content, you can use the bricks/posts/query_vars filter to unset the s= parameter and apply a Meta Query. Here’s a simplified example:

add_filter('bricks/posts/query_vars', function($query_vars, $settings, $element_id) {  
    if ($element_id === 'your_query_loop_id') {  
        $search_term = '';  
        if (isset($query_vars['s'])) {  
            $search_term = $query_vars['s'];  
            unset($query_vars['s']);  
        }  

        if (!empty($search_term)) {  
            $query_vars['meta_query'] = [  
                'relation' => 'OR',  
                [ 'key' => 'field_1', 'value' => $search_term, 'compare' => 'LIKE' ],  
                [ 'key' => 'field_2', 'value' => $search_term, 'compare' => 'LIKE' ],  
            ];  
        } else {  
            $query_vars['meta_query'] = [  
                [ 'key' => 'field_1', 'value' => 'nonexistent_value', 'compare' => 'LIKE' ],  
            ];  
        }  

        $query_vars['post_type'] = 'your_cpt';  
    }  
    return $query_vars;  
}, 1000, 3);  

Note: Disable “Query Bricks data in search results” in Bricks Settings → Miscellaneous to prevent searching in post_content.

Big thanks to Jenn and the community for the help! :pray: