• Hey there,
    thanks for this awesome plugin.

    We just installed and configured same. It works right out of the box – well done!

    Do you know a good approach to pass additional filters e.g. a category based on the visitors selection?
    For example we have a search form and a category dropdown. Any documentation i can follow for same?


    Thanks in advance.

    Cheers,
    Kjell

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Karan

    (@kjswp)

    @sfdeveloper

    You can filter search results by category in your live search by using a custom hook searchwp_live_search_query_args

    Example:

    add_filter('searchwp_live_search_query_args', 'filter_live_search', 999);
    
    function filter_live_search( $args ) {
    $args['tax_query'] = array(array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => 'uncategorised',
    ));
    
    return $args;
    }

    Thread Starter sfdeveloper

    (@sfdeveloper)

    @kjswp thanks for your reply and example.
    I guess this only works if i want to filter a specific category. In my screenshot you can see that the category can be selected by the visitor as well.
    Pretty sure the value of this dropdown won’t be available within searchwp_live_search_query_args. I mean i won’t be able to fetch it via $_POST because the ajax-search does not care about any other form fields.

    Maybe there is a way to add custom attributes to the input [data-swplive=”true”] to get passed as well? I could then change this attribute on change of the category dropdown.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pass additional filter’ is closed to new replies.