Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Search filter for specific product category

Viewing 6 posts - 1 through 6 (of 6 total)
  • Branimir Borisov
    #2795

    Hi,

    Not sure if this is realted to the following topic here: https://support.searchandfilter.com/forums/topic/results-showing-from-excluded-categories/, but I was not able to achive what I want with the solutions there.

    So the idea is to have a search filter, which works only with a specific product category. This includes all taxonomies which are listed in the search form/filters to be for products from this category and the products that are also listed as result to be only from that category.

    Can you give any advise on how to do that?

    Thanks in advance

    Ross Moderator
    #2881

    Hey there, just to let you know I will be looking at this tonight.

    Thanks

    Branimir Borisov
    #2892

    Hi Ross,

    I’ll be waiting for your replay.

    Thanks.

    Ross Moderator
    #3004

    Hey Branimir sorry this slipped through the net, I’ll try to take a look later or tomorrow.

    Thanks

    Dan Mahoney
    #3065

    I think I may be looking for the same thing, if I understand the original post correctly. I have a content type with a few taxonomies, and have set up filters on a particular page to search among them. Works great.

    Elsewhere on the site, I want to set up the same search filters, but I want the possible search results to be restricted to those where a particular value in a particular custom taxonomy is selected. I think this is the same as Branimir’s goal to restrict results to a particular product category.

    Thanks in advance for any help!

    Ross Moderator
    #3107

    Hey both please see this thread:

    https://support.searchandfilter.com/forums/topic/excluded-categories-on-specific-forms/

    Does this look like what you are trying to achieve? The code from that thread is below (just add to functions.php):

    function modify_search_filter_query( $query )
    {
        global $sf_form_data;
    	global $wp_query;
    	
        if ( $sf_form_data->is_valid_form() && $query->is_main_query() && !is_admin())
        {
    		
    		if($sf_form_data->form_id()==12) //where the form ID is 12
    		{
    			//modify the query for a form with id 12
    			$query->set( 'cat', '-2' );
    		}
    		else if($sf_form_data->form_id()==99) //where the form ID is 99
    		{
    			//modify the query for a form with id 99
    			$query->set( 'cat', '-20' );
    		}
    		
        }
    }
    add_action( 'pre_get_posts', 'modify_search_filter_query', 21 );

    You can get the ID of the form by looking at the URL in the edit screen (when editing your S&F form)

    http://www.yoursite.com/wp-admin/post.php?post=797&action=edit

    In this case it would be 797.

    Hope that helps 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.