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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Ross Moderator
    #2881

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

    Thanks

    Anonymous
    #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

    Anonymous
    #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 5 posts - 1 through 5 (of 5 total)