Forums › Forums › Search & Filter Pro › Dynamic filtering on custom template
Tagged: V3
- This topic has 13 replies, 3 voices, and was last updated 6 years, 3 months ago by Ross.
-
Anonymous(Private) August 14, 2018 at 2:22 pm #185496
Hi,
We’re currently building a custom template for one of our clients, that will allow them to create a few landing pages. The client provides tours, and one of the taxonomy’s of a tour is the country. The first few landing pages will be made for countries, but they will be separate from the taxonomy archive pages.
Now, on our custom template, we let the client choose the desired country for the page through an ACF field. We can then take that value and add it to our wp_query. However, when we want to add a filter to the page we are running into two issues;
1. How do we make sure a visitor can only filter in the desired taxonomy?
It seems like when we add the s&f id to the query, it overrules the desired taxonomy. Now, I am aware we can include specific taxonomy’s in the settings of S&F, but that would mean that the form is not dynamic. That would in turn mean we will have to make a separate filter for each taxonomy. Is there a way around this?2. Currently the only way we get the filter to display results in is by setting the ‘display results’ option to ‘custom’. This does require us to add a url, but we don’t know the url of a page yet, since our client will be making their own through our custom template.
I’m sure you can help us out,
Thanks in advance.Barry
Trevor(Private) August 14, 2018 at 4:15 pm #185535Ah, well, you might be able to use this filter:
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
To set the default value in that field, based on the page you are on.
Anonymous(Private) August 15, 2018 at 8:40 am #185620Hi Trevor,
I was able to get a default option selected through the code you provided. However, this did not change the state of the search form, meaning that the other selects in the filter form still had all the options, as if no country was selected. I will paste the code I used below;
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sft_trip-country[]')||($input_object['type']!='select')) { $input_object['defaults'] = array('germany'); } return $input_object; }
As you can see, i’m manually selecting ‘germany’, because I could not get it to work dynamically with this code;
$input_object['defaults'] = array($country_choice);
Any ideas what i’m missing? Should I perhaps also change the url to add the search parameter like;
/?_sft_trip-country=$country_choice
Thanks in advance!
-
AuthorPosts