Forums › Forums › Search & Filter Pro › Pre-filtered results page
- This topic has 11 replies, 2 voices, and was last updated 6 years, 4 months ago by Trevor.
-
Anonymous(Private) June 15, 2018 at 1:29 am #180439
Currently I’m using a single search form with a custom results.php template and displaying that via shortcode. I want to duplicate the exact same thing except I’d like to show pre-filtered results, e.g. results that have a certain dropdown value already selected when the page loads. This would allow me to create “curated content” pages with results from a specific category, for instance, and a custom URL. How can I do this? I can’t find anywhere in the search fields options to set a default value.
Thanks in advance!
Trevor(Private) June 15, 2018 at 8:22 am #180446There isn’t a way to pre-select certain filter values, but it depends on how you want to do this, as you may be able to do it in another way.
Do you want these ‘curated content’ pages to be the same as the results page, or on their own page, and do you want to be able to change the results via the form on that page, or do you want (if the user chooses to search onwards) to start afresh on the normal results page?
Anonymous(Private) June 15, 2018 at 6:32 pm #180519Hey Trevor,
If possible, I’d like the curated content pages to use the same results.php template because I’d like the styling of the results to be consistent across the site. However they should be their own page, with their own unique URL for SEO reasons. On these pages, I would not surface the search bar at all, so the user wouldn’t be able to change the results in any way.
Trevor(Private) June 16, 2018 at 8:49 am #180538What you could do, and I have done this before, is duplicate the form.
Remove from the Form UI all the elements/fields.
Then, in the form design tabs;
Posts
Categories, Tags and Taxonomies
Post MetaSet up the rules for the pre-filter. Then place only the results shortcode for that form on the desired page.
And do this for each curated page.
Anonymous(Private) June 16, 2018 at 5:51 pm #180556So I actually did try doing this, but was unable to get the post meta rules to work. On this site, the posts that I’m trying to return as results have a bunch of ACF fields attached to them (most of them arrays with multiple checkbox values). One of these fields is called property_type and it’s values include 4 options, one of which is called home_only. I tried creating a curated page called “Home Only” which I’d like to display all posts that have this home_only value selected (all other values are irrelevant, i.e. I only want to filter out posts that don’t have this value). So I created a post meta rule that targeted this field, had the type set as char, the condition as “exists” and the value as ‘home_only’ (I also tried Home Only, home_only, etc) but it always displays every result, including ones where home_only is not selected. Something tells me I’m not setting up the post meta rule properly, but I’m not sure how it’s supposed to be formatted.
If it might be easier for you to just take a look at my site, let me know. Thanks again.
Anonymous(Private) June 20, 2018 at 1:25 am #180748Hey Trevor,
This seems to work. However, I’m facing a new problem now. Is there any way to enable OR logic on the post meta filtering? E.g. I’m trying to create a page where property_type is the meta in question. This field has 4 available values, let’s just say A, B, C, and D. I’m trying to omit results that ONLY have A checked, i.e. display results that have either B, or C, or D filled. Is this possible?
Also – any idea why ajax infinite scroll only works on the very first form/results object I created? All the subsequent ones are broken. I tried setting the infinite scroll container class name in addition to the post/result class but it didn’t have any effect.
Trevor(Private) June 20, 2018 at 1:18 pm #180777Hi
Conditions set in that Post Meta tab are added with AND. You would have to do them instead by hand coding it using our Edit Query Arguments filter to add an extra argument.
On the Infinite Scroll thing, you have made multiple forms, but only one works with Infinite Scroll?
Anonymous(Private) June 20, 2018 at 9:37 pm #180865Hey,
So I attempted to add additional arguments and tested it with my original search form/results page and received this error – Warning: trim() expects parameter 1 to be string, array given in /home/andreymh/public_html/v2/wp-includes/class-wp-meta-query.php on line 577
This is the argument code I put in functions.php –
function filter_function_name( $query_args, $sfid ) {
//if search form ID = 225, the do something with this query
if($sfid==12)
{
//modify $query_args here before returning it
$query_args = array(
‘meta_key’ => ‘property_type’,
‘meta_compare’ => ‘LIKE’,
‘meta_value’ => array(
‘modular_with_land’,
‘manufactured_with_land’,
‘mobile_with_land’
)
);
}return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );In this case 12 is the ID of the main search page form, not the curated page I want this to actually be applied to (which I’m not sure how that will work since that page only has a results shortcode).
As for the infinite scroll, yes. I created a search form for the main search page and then duplicated it to create the curated pages. On those forms, I deleted all the fields from the form UI per your suggestion, changed what URL the results get displayed on, and changed the post meta filters.
-
AuthorPosts