Forums Forums Search & Filter Pro Results in tabs

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

    Trevor
    #226840

    I do not think that you can do as you want, using tabs. The string in the URL, and separating the results like that into different tabs, would not be possible, sorry.

    Anonymous
    #226844

    Thank 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
    #226854

    You 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
    #226865

    Thank 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
    #226957

    I 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
    #227006

    The 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
    #227051

    It 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
    #227062

    You 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…

    Trevor
    #227113
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 16 total)