Home › Toolset Professional Support › [Resolved] filter button "past" and "future"
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 13 replies, has 2 voices.
Last updated by alexd-6 1 year, 9 months ago.
Assisted by: Minesh.
Hi,
i have and posttype termine which has an date field with time.
And i have a view as custom search, which should have a button for "past" and "future" for show post only "older" or "newer" posts from TODAY()
I dont find anything in Support-Forum about.
is this possible?
thx for an answer,
best regards - Alex
Hello. Thank you for contacting the Toolset support.
As I understand - you added two buttons to your view one that should display the old events and one button that should display the future events. - is that correct? If yes:
- What view you are using - Are you using classic or block view?
- how exactly you have added those buttons?
If you can share admin access details and problem URL where you added your view I can review your current setup and that will help me to guide you in the right direction.
*** 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.
So what if you create a two views - one view that should display posts in future and one view that should display old (past) posts and you should also create two pages and link the URL of those pages to the buttons.
Does that makes sense?
hi minesh,
can we do this not with a filter?
And: can we sort about the date in field "eventdate"?
thx - alex
I share you the straight forward way as with the filter it might require custom code.
And: can we sort about the date in field "eventdate"?
==>
Do you mean you want to compare the old (past) and future posts with the custom everntdate field and also want to order by everntdate custom field?
Hi,
yes that would be great.
Sorry I do not get what you want exactly yet.
Can you please share brief information about with that way you want to go and do you have custom date field that holds the startdate?
Hey - at all:
its just look like a simple event (cpt termine) listing orderd by "eventdate". Filter should be "future" -> all post from today, "past" -> all posts from today in past. "search" to search all events text.
i did it in view 2824
hidden link
you know what i mean?
best regards - alex
What I'm asking is - you want to compare the custom field "eventdate" or default post publish date to compare the future and past post?
i want eventdate to compare both, future and past
thx - alex
Can you please check now: hidden link
I've added the Past and Future links at top of the page within your search and pagination section of your view:
- hidden link
<div class="form-group"> <a href="?past=1"> Past </a> | <a href="?future=1"> Future </a> </div>
Then with the "Custom Code" section offered by Toolset, I've added the code snippet "toolset-custom-code" and added the following filter code to it:
=> hidden link
add_filter('wpv_filter_query', 'func_show_past_future_posts', 99, 3); function func_show_past_future_posts($query, $setting, $view_id) { global $wpdb; if($setting['view_id'] == 2824) { if(isset($_GET['past']) and $_GET['past'] == 1 ) { $query['meta_query'][] = array( 'key' => 'wpcf-eventdate', 'value' => time(), 'type' => 'UNSIGNED', 'compare' => '<' ); } else if(isset($_GET['future']) and $_GET['future'] == 1 ) { $query['meta_query'][] = array( 'key' => 'wpcf-eventdate', 'value' => time(), 'type' => 'UNSIGNED', 'compare' => '>' ); } } return $query; }
Can you please confirm it works as expected now.
Hi Minesh - thx a lot this is working like a charm! - Why isnt it available in filters for the view? i think this where a nice feature.
One question about sorting in this view that you edited:
i sort it on field "eventdate" - asc - can i use in case "past" desc and in case "future" sort asc? - That would be great.
thx and best regards
alex
Can you please check now: hidden link
I've adjusted the code as given under with the "Custom Code" section offered by Toolset:
=> hidden link
add_filter('wpv_filter_query', 'func_show_past_future_posts', 999, 3); function func_show_past_future_posts($query, $setting, $view_id) { global $wpdb; if($setting['view_id'] == 2824) { if(isset($_GET['past']) and $_GET['past'] == 1 ) { $query['meta_query'][] = array( 'key' => 'wpcf-eventdate', 'value' => time(), 'type' => 'numeric', 'compare' => '<' ); $query['orderby'] = array( 'meta_value_num' => 'DESC'); $query['meta_key'] = 'wpcf-eventdate'; // } else if(isset($_GET['future']) and $_GET['future'] == 1 ) { $query['meta_query'][] = array( 'key' => 'wpcf-eventdate', 'value' => time(), 'type' => 'numeric', 'compare' => '>' ); $query['orderby'] = array( 'meta_value_num' => 'ASC'); $query['meta_key'] = 'wpcf-eventdate'; // } } return $query; }
I hope everything is resolved now and feel free to open a new ticket with every new question you may have. You can mark resolve this ticket.
Hi Minesh - thx a lot it works perfect! - best regards, warmly - alex