Redirect search filters form to the same category page when searching within a category

Hi,

I use listinghive theme and I would like to know if there is a way to stay within a category page when filtering listings.

When the user is on a category page, on filter form submission, the URL changes to the home URL with the encoded filters. Here is an example:

I tried changing the action URL of the filter form using this hook:

function add_listing_filter_form_filter( $form ) {
    $form['action'] = hivepress()->router->get_current_url();
    return $form;
}
add_filter('hivepress/v1/forms/listing_filter', 'add_listing_filter_form_filter', 1000);

The redirection works well and the URL remains on the category page with the encoded filters, but the problem is that the filters are not applied and all listings in the category are displayed.

Thank you for the support.

Hi,

It’s possible, but requires code customizations. It would be hard to change the current search logic as it relies on WordPress search and it requires the “s” parameter in the URL query. If you want to keep the category header for category-specific search, it may be easier to embed the category header into the search result pages when a specific category is selected in the search filters. For this, you can use a filter hook available in ListingHive header, please check how the current header is rendered here listinghive/includes/components/class-theme.php at master · hivepress/listinghive · GitHub For example, you can check if it’s the search page and if the “_category” parameter is available in the URL query, and render the category header if needed.

Hope this helps

Hi ihor,

Indeed, I thought of such solution too, I’ll go for that then.

Thank you very much for the quick reply!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.