Forums Forums Search & Filter Pro Dynamic filtering on custom template

Tagged: 

Viewing 10 posts - 1 through 10 (of 14 total)
  • Anonymous
    #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
    #185521

    Let us take this one step at a time. The taxonomy you refer to here:

    How do we make sure a visitor can only filter in the desired taxonomy?

    Is that the country (which you said was also an ACF field)?

    Anonymous
    #185526

    Hi Trevor,

    Thanks for the quick reply.
    Yes, that would be a country. To be clear; the ACF field is just a taxonomy select field, in order to let the client choose the country to base the page on.

    Trevor
    #185531

    Is that taxonomy a field within the form on the page (or could it be made to be, even if hidden)?

    Anonymous
    #185533

    It’s not a field yet, but I could make a field for it, sure. How would we fill it with the right value though?

    Trevor
    #185535

    Ah, 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
    #185620

    Hi 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!

    Anonymous
    #185622
    This reply has been marked as private.
    Trevor
    #185639
    This reply has been marked as private.
    Anonymous
    #185967

    Hi Trevor/Ross, do you have any updates on this issue?

Viewing 10 posts - 1 through 10 (of 14 total)