Startseite › Toolset Professional Support › [Gelöst] I'm trying to make a view that only shows past events.
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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)
Dieses Thema enthält 39 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von Minesh vor 1 Jahr, 2 Monaten.
Assistiert von: Minesh.
Any update on this? Also https://toolset.com/forums/topic/im-trying-to-make-a-view-that-only-shows-past-events/page/3/ redirects me to https://toolset.com/forums/topic/im-trying-to-make-a-view-that-only-shows-past-events/ now so I can't even see the third page of this thread.
What we are doing is as you requested we are only displaying the past events with the view that you created to display the past event by default when page loaded first time.
Now what happens is, when you select the date as 14th may and select vendor fees filter to yes, it will display posts where date equal to 14th and vendor fees equal to yes.
I see it working here:
- versteckter Link
How you want to apply the multiple filters?
Now use any filter and not the date filter and the view reverts back to past and future as I mentioned in my previous reply.
I know now what you mean.
I see now when I remove the filter it does show the correct past event:
- versteckter Link
I've adjusted the code added to "Custom Code" section as given under for both future and past event views:
add_filter( 'wpv_filter_query', 'func_filer_show_past_events', 99, 3 ); function func_filer_show_past_events( $query_args, $view_settings, $view_id ) { if( $view_id == 4224 and !isset($_GET['wpv_view_count'])) { $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => "<", 'type' => 'numeric' ), ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; }else{ if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { $meta = $query_args['meta_query']; foreach($meta as $k=>$v): if($v['key'] == 'wpcf-date-ce'){ $filter_array = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce'], 'compare' => ">=", 'type' => 'numeric' ), array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce']+86400-1, 'compare' => "<=", 'type' => 'numeric' )); $query_args['meta_query'][] = $filter_array; unset($query_args['meta_query'][$k]); break; } endforeach; }else{ $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => "<", 'type' => 'numeric' ), ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; } } return $query_args; } add_filter( 'wpv_filter_query', 'func_filer_show_future_events', 99, 3 ); function func_filer_show_future_events( $query_args, $view_settings, $view_id ) { if( $view_id == 4288 and !isset($_GET['wpv_view_count'])) { $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => ">", 'type' => 'numeric' ) ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; } else{ if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { $meta = $query_args['meta_query']; foreach($meta as $k=>$v): if($v['key'] == 'wpcf-date-ce'){ $filter_array = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce'], 'compare' => ">=", 'type' => 'numeric' ), array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce']+86400-1, 'compare' => "<=", 'type' => 'numeric' )); $query_args['meta_query'][] = $filter_array; unset($query_args['meta_query'][$k]); break; } endforeach; }else{ $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => ">", 'type' => 'numeric' ) ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; } } return $query_args; }
Thank You, but now the views display no results at all. Even with no filters being used.
You asked for the past view to display only past events on the following page:
- versteckter Link
When I remove the filter - I can see there is no past event, as you can see now as I removed the filter, as you can see it shows all future events:
- versteckter Link
That is why its not displaying any post as there is no past event available. (currently I removed the filter so you can see all events those are belongs to future not past).
Let me know once you review that and I'll apply the past event filter again.
No, there are plenty of past events. Now even the default original that should show all(past and future) is blank as well: versteckter Link
The past view now only shows future: versteckter Link
If you look at the backend of the Community Events CPT: versteckter Link
You can see past and future events. Like this past one: versteckter Link
Can you please check now: versteckter Link
I've adjusted the code for both past and future events as given under:
add_filter( 'wpv_filter_query', 'func_filer_show_past_events', 99, 3 ); function func_filer_show_past_events( $query_args, $view_settings, $view_id ) { if( $view_id == 4224 and (!isset($_GET['wpv_view_count']) or (isset($_GET['wpv-wpcf-date-ce']) and empty($_GET['wpv-wpcf-date-ce']))) ) { $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => "<", 'type' => 'numeric' ), ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; }else if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { $meta = $query_args['meta_query']; foreach($meta as $k=>$v): if($v['key'] == 'wpcf-date-ce'){ $filter_array = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce'], 'compare' => ">=", 'type' => 'numeric' ), array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce']+86400-1, 'compare' => "<=", 'type' => 'numeric' )); $query_args['meta_query'][] = $filter_array; unset($query_args['meta_query'][$k]); break; } endforeach; } return $query_args; } add_filter( 'wpv_filter_query', 'func_filer_show_future_events', 99, 3 ); function func_filer_show_future_events( $query_args, $view_settings, $view_id ) { if( $view_id == 4288 and (!isset($_GET['wpv_view_count']) or (isset($_GET['wpv-wpcf-date-ce']) and empty($_GET['wpv-wpcf-date-ce']))) ){ $args = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => strtotime('23:59:59'), 'compare' => ">", 'type' => 'numeric' ) ); // add these arguments to your meta query $query_args['meta_query'] = isset($query_args['meta_query']) ? $query_args['meta_query'] : []; $query_args['meta_query'][] = $args; } else if(isset($_GET['wpv-wpcf-date-ce']) and !empty($_GET['wpv-wpcf-date-ce']) and is_numeric($_GET['wpv-wpcf-date-ce']) and $_GET['wpv-wpcf-date-ce']>0) { $meta = $query_args['meta_query']; foreach($meta as $k=>$v): if($v['key'] == 'wpcf-date-ce'){ $filter_array = array( 'relation' => 'AND', array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce'], 'compare' => ">=", 'type' => 'numeric' ), array( 'key' => 'wpcf-date-ce', 'value' => $_GET['wpv-wpcf-date-ce']+86400-1, 'compare' => "<=", 'type' => 'numeric' )); $query_args['meta_query'][] = $filter_array; unset($query_args['meta_query'][$k]); break; } endforeach; } return $query_args; }
I've checked on load it shows correct past event, then when I select date filter it dhows correct selected date event and when I remove the date filter it again shows the correct past event and when I select the fees filter it shows the correct event.
I think that did it. Thank You. I'm going to push it to the live site tomorrow and I'll let you know how it goes.
Glad to know that now all issues are address with the past and future event views. You're welcome to mark resolve this ticket when you can.
Apologies. I thought I already closed this. Everything is working great on the production site. Thank You for all your help and I hope you have a great week!