Skip Navigation

[Resolved] Filter view by dates – need more advance tutorial

This support ticket is created 5 years, 2 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Beda 5 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1340357

I have post with custom field DateTime type "Appointment DateTime"

1. I need view, there will be all posts with "Appointment DateTime" within day, I will choose by param.
How could I do it?

2. Also is any possibility to find all Posts with "Appointment DateTime" in the same day as current post?

3. Is any possibility to show post, there "Appointment DateTime" is next or previous as current post (like "next appointment" or "previous appointment")

4. Is any possibility to edit view filter not by user interface but as a code? It looks like filters is really more powerfull then it is possible to setup by user interface.

#1340359

You can see here how to set up such filters:
https://toolset.com/documentation/user-guides/date-filters/

You should work with NUMBER options, and use the TODAY() or any other placeholder for dates in the queries.

So, for example, set the filter to "number equal to today" for your goal #1 or "number equal past_day/future_day by as how many days into the past or future you want the posts of.

Views filters are made to avoid code, so generally, there is less opportunity in code than GUI, using WordPress and Toolset, however, we have an API that helps to filter views in several aspects. Is it this you are looking for?
https://toolset.com/documentation/programmer-reference/views-filters/

#1340387

Oh, thanks a lot, I just missed part about NUMBER as format in documentation.

But its still not clear how to use it.

Then I choose number, I still can't change param of date. I have to choose param for DATE(dd,mm,yyyy) in interface as exact day, month, year.
My point is that I need it dinamically, depend on post, there it is inserted.

So, issue #1 is still here:
"So, for example, set the filter to "number equal to today" for your goal #1 or "number equal past_day/future_day by as how many days into the past or future you want the posts of." - this is not exactly what I need, because I need it not for today as real today, but for the date of post there it is displayed.

So, I have Post1 with AppointmentDate as 12 Sep 2019, 10:00 am
I need to choose all other posts with the same date "12 Sep 2019" but any time in this day.

How exactly could it be in filters?

#1341769

Well, as I mentioned, you will compare the date field as a number to TODAY() for example, that can be chosen right in the Query Filter editor as described in the doc as well.
That's dynamic. It will always be TODAY() (today).

The first screenshot on that Documentation shows exactly the filter you mention to want.

#1341967

This is not what I'm looking for. As you described (and how it is in documentation) TODAY() has no params and it is for today (as absolute today, like TODAY() is 17 Sep 2019). So, I need different - I need day from param.
Let's say I could transfer date of Appointment to the view and it is "12 Sep 2019, 10 am" (in numbers as unix timespan). So, I need filter that will show all Appointments with appointmentdate field like "12 Sep 2019" (e.g. at 9 am, 12 am, 2pm, etc.)

#1341985

TODAY() will compare against the date it is currently, so today it'll compare against 17th September 2019, tomorrow against 18th September 2019, and so on.

I understand instead you want to compare several posts to a date stored in one post of the same kind.

Probably you want to insert this View to a Post that has a data, and then display all the other posts within the same day but not hour.
Kind of a "see other slots" for appointments the same day.

This is not possible natively in Views, because the Field, will always return a precise timestamp.

So you would have to create a Custom ShortCode that returns lets say either the previous and next midnight's timestamp relative to the time stored in the Custom Field.
That Custom ShortCode, can then be used as a max and min value passed in Toolset Views as ShortCode Attributes in the Query.

The Views Query allows to filter posts any Date Field (as a number) between a max and min value passed as ShortCode Attributes (or URL, if you prefer), so what's needed is the custom logic, that gets the current posts date field timestamp and derogates the previous and next midnight.
Those are then our min and max values, which will depend on the post where the View is inserted.

The View, when inserted, in this case will need the ShortCode parameters min and max set, which you will populate with the Custom ShortCode (which does all the logic of calculating the past and next midnight).

Please let me know if you need help with this. I can assist along and suggest next steps, however if you'd require assistance for a ready to go development then Toolset Contractors would be a better choice: https://toolset.com/contractors/