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.
Tell us what you are trying to do?
I have a view for events custom post type. Events have a custom field for Date. I want this view to only show past events based on today's date. When I go to the view and add a filter. The date custom field does not show in the options to filter by.
Is there any documentation that you are following?
https://toolset.com/documentation/legacy-features/views-plugin/date-filters/
Hello. Thank you for contacting the Toolset support.
I would like to know that have you created Events custom post type and custom date field using Toolset Types plugin or you are using third party events plugin? Can you please share how you configure the custom date field?
Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/
Thank You. It's attached. The date field in question has a slug of "date-ce" and is being used on the "community-event" CPT.
You should filter your view by your custom date field lower than equal to Now() by adding a query filter from query filter section of your view.
For example:
Select items with field: your date field is a UNSIGNED lower than or equal NOW()
To do that, you should edit your view and navigate to "Query Filter" section and add query filter for your custom date field and select "UNSIGNED" and further select "lower than" further select NOW().
More Info:
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
=> https://toolset.com/documentation/user-guides/date-filters/
Please re-read my initial request. I'm telling you that my custom field of date-ce is not listed in the query filter options.
That is really strange. Can you please share the view you created and also share the admin access details and let me review your current setup and check whats going wrong with your setup.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Before we do that. I might have found the issue. I have a user filter for the same date-ce field. When I remove that filter I can use the view filter for that field.
Is it possible to have the filter on the view and a filter in the search section be based on the same field?
Yes - we can do that but before I say anything I will have to review your current structure.
You want that the posts displayed by view should be past date posts and then user should also be able to filter the post with the same date field - correct? If yes:
I need to review your views settings first.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
As you have a user filter available - how you want that it should work.
- When view is displayed you only want to display past posts and when user select the date from the frontend filter - do you still want to display past posts based on the selected date by the user from the frontend?
Correct.
I've added the following code to the "Custom Code" section offered by Toolset with the code snippet "toolset-custom-code":
=> versteckter Link
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; } return $query_args; }
And with your view's "Query Filter" section I've change your custom date filter as given under:
=> versteckter Link
Date is a number lower than URL_PARAM(wpv-wpcf-date-ce)
Can you please confirm it works as expected now.
Thank You. This looks great. I also need to make one for a future view. I've duplicated the past view to this view for the future: versteckter Link
So I've changed the query filter for your view as given under:
=> versteckter Link
Date is a number greater than URL_PARAM(wpv-wpcf-date-ce)
Also, added the following filter code to "Custom Code" section offered by Toolset with code snippet "toolset-custom-code":
=> versteckter Link
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; } return $query_args; }
I just went back and checked the past view and when I select a date it in the filter front view it doesn't actually filter by date.
Can you please share with what view you have issue with and on what page you have added that page and you want to filter with what future or past event?