Forums › Forums › Search & Filter Pro › Search filter for specific product category
- This topic has 5 replies, 3 voices, and was last updated 10 years, 11 months ago by
Ross.
-
Ross Moderator(Private) July 24, 2014 at 1:42 pm #2881
Hey there, just to let you know I will be looking at this tonight.
Thanks
Ross Moderator(Private) July 28, 2014 at 7:44 pm #3004Hey Branimir sorry this slipped through the net, I’ll try to take a look later or tomorrow.
Thanks
Anonymous(Private) July 29, 2014 at 8:50 pm #3065I 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(Private) August 1, 2014 at 1:19 am #3107Hey 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 🙂
-
AuthorPosts