Forums › Forums › Search & Filter Pro › Results in tabs
- This topic has 15 replies, 3 voices, and was last updated 6 years, 4 months ago by
Trevor.
-
Anonymous(Private) November 15, 2019 at 1:09 pm #226830
I’m using a search form on an archive-events page which works well.
I’d like to be able to separate the results onto two separate tabs eg. past events/future events.
The page loads with future events as the default active tab and entering criteria into the search form correctly shows future events which meet the criteria entered however… switching to the past events tab loses the settings in the search form and/or resets the whole page (as the url changes from mysite/events/ to mysite/events/?etype=past) and hence ALL past events are shown.
I appreciate this may be an issue with the way the tabs are handled rather than S&F that is “at fault”, but just wondering if you’ve come across this scenario before and might have any suggestions?
With many thanks in advance.
Anonymous(Private) November 15, 2019 at 4:08 pm #226844Thank you Trevor… what is shown in the tabs seems to be controlled by adding a $where to the query_args depending on whether events are past or future so if I could somehow “persist” the S&F query at the same time, it feels as if it *should* be possible.. but I appreciate it’s probably beyond the scope of general support and I’ll investigate further on my own.
Trevor(Private) November 15, 2019 at 5:43 pm #226854You can add to the query using this filter:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
It takes the same arguments as wp_query()
Anonymous(Private) November 15, 2019 at 8:14 pm #226865Thank you again… I’m thinking that may be the way to go… somehow.
Incidentally, did I read elsewhere that For the date filtering to work in Search and Filter, the dates must be stored in the yyyymmdd format? And yet you can filter on the post_date which is a date timestamp? Does that only work specifically for the post_date?
Trevor(Private) November 18, 2019 at 5:43 pm #226957I am not sure if it would work with a date timestamp, but might work with other formats of date. The key is to have it in a format where the year comes first, then the month, then the day, so that sorting will work.
You could always set up a few test posts to see if it would work in the format you want to use?
Anonymous(Private) November 19, 2019 at 12:42 pm #227006The template I’m using for the above has so many filters already built into it, that rather than attempting to add to the S&F query as suggested above, I’m considering taking a different approach and adding the S&F query to what already exists in the template eg.
The information for the “Upcoming events” tab is currently generated as follows –
if ( isset( $_REQUEST['etype'] ) && $_REQUEST['etype'] == 'upcoming' ) { $today = date_i18n( 'Y-m-d H:i:s' ); $where .= " AND ($wpdb->posts.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='set_end_time' and date_format($wpdb->postmeta.meta_value,'%Y-%m-%d %H:%i:%s') >'" . $today . "')) ";}I know I can access a single S&F field by name so could build an additional $where clause to add to the above (there are actually only 4 search fields so this wouldn’t be too time-consuming) but is there a better way to access ALL the criteria in the S&F form and convert into a $where?
Also do you foresee any other potential issues with this approach?
With many thanks in advance for your thoughts.
Trevor(Private) November 19, 2019 at 5:22 pm #227051It is not something I have tried. You seem to be directly accessing the database, rather than using the wp_query() function, and adding your additional arguments to that. If you do that, THEN you can add search and filter to it as an additional argument, like this:
['search_filter_id'] => 1234;or use pre_get_posts or query_posts, as shown in this page:
https://searchandfilter.com/documentation/search-results/custom/
But the form may then need to be set to Custom method, which requires a single, specified, results URL.
Anonymous(Private) November 19, 2019 at 5:51 pm #227062You seem to be directly accessing the database, rather than using the wp_query() function, and adding your additional arguments to that.
Unfortunately that is what I am stuck with since it’s the way the theme I’ve been asked to work with works and tbh it’s what’s causing a lot of my problems.
When you say, “if you do that” I assume that you mean if I was using the wp_query() function?
The theme does also use pre_get_posts which I’ve attempted to modify with
function pre_get_posts_function($query) { //this would be a pre_get_posts you already have in place somewhere //then set <code>search_filter_id</code> $query->set("search_filter_id", 13175); } add_action( 'pre_get_posts', array('event_manager_pre_get_posts', 'pre_get_posts_function'), 2000 );… but that doesn’t appear to have had any effect, maybe because other filters or criteria ($where clauses as outlined above) are subsequently added or maybe because the form is not set to Custom method?
No worries if you’ve no idea… I’ll keep pondering…
-
AuthorPosts