Skip Navigation

[Resolved] Filter by start-datetime and just show upcoming events

This thread is resolved. Here is a description of the problem and solution.

Problem:
Filter by start-datetime and just show upcoming events

Solution:
you need to add the add-on query filters using the view's filter hook "wpv_filter_query"

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/filter-by-start-datetime-and-just-show-upcoming-events/#post-1220418

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by TorstenR3514 5 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1219874

Tell us what you are trying to do?
I'am trying to just show upcoming events in the list at:
hidden link

It works fine with my shortlist at the startpage under: hidden link with the Query Filter " Select items with field: Kurs Start is a string greater than or equal TODAY()"

But at the upper list i allready filter "Select items with field: Kurs Start is a string greater than or equal URL_PARAM(wpv-wpcf-kurs-start)" to give the user the ability to filter der events by kurs-start, so that I can't pick a second filter for the same field: " Select items with field: Kurs Start is a string greater than or equal TODAY()"

Solution?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1220336

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - as I understand, you want to filter the events using the initial filter to filter by :

 Select items with field: Kurs Start is a string greater than or equal TODAY()"

As well as you want to filter the products and apply the filter on Kurs Start using URL Param?

#1220343

yes

#1220344

events that are in the past shouldn't be displayed.

#1220365

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - you need to add the query filters using the view's filter hook wpv_filter_query

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

If you can share access details and I would be happy to add query filter for you.

#1220418

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

well - I've added the following filter code to "Custom Code" section offered by Toolset:

add_filter( 'wpv_filter_query', 'func_show_future_events_today', 10, 3 );
     
function func_show_future_events_today( $query_args, $view_settings, $view_id ) {
    if (in_array($view_id, array(48) ) and !isset($query_args['meta_query']) ) {
        
        $query_args['meta_query'] = array(array(
                                 'key'=>"wpcf-kurs-start",
                                 'value'=>time(),
                                 'type'=>"numeric",
                                 'compare'=>">=")); 
         
    }
    return $query_args;
}

=> hidden link

Can you confirm - the view works as expected?

#1220512

Yes it does! Thx a lot! So many i don't know!

array(48) apllies the function to the view "bildungsangebot-liste" view_id=48 (Took me ages to find the relation ;).
Is it possible to applie one function to more than on id?

#1220748

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - if you want to apply the same filter view to multiple view IDs, you can use the following code:

For example:

add_filter( 'wpv_filter_query', 'func_show_future_events_today', 10, 3 );
function func_show_future_events_today( $query_args, $view_settings, $view_id ) {

    $arr_view_ids = array(48,999,888);  // add your view ids here
    if (in_array($view_id, $arr_view_ids ) and !isset($query_args['meta_query']) ) {
         
        $query_args['meta_query'] = array(array(
                                 'key'=>"wpcf-kurs-start",
                                 'value'=>time(),
                                 'type'=>"numeric",
                                 'compare'=>">=")); 
          
    }
    return $query_args;
}
#1220767

My issue is resolved now. Thank you!