Skip Navigation

[Resolved] Date and "Budget" Filter

This support ticket is created 6 years, 3 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 6 replies, has 2 voices.

Last updated by pedro.S 6 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1114436

Tell us what you are trying to do?

Picture this scenario:

I want to sell tickets for events.

Tickets for Events is a Woocommerce product.
Extending Woocommerce fields with Toolset, i inserted 1 date field with time (always there) and another date field with time that is a conditional field (for events that take more then 1 day). So it's startdate and finishdate. Some times the finishdate field is blank (events that take only 1 day).

The product has also a field that is a location, based on Google Maps.
And also a price (normal stuff for Woocommerce).

I want to add a filter on the listings main page that allows the following:

By Period of time.
Events that will happen:
today
tomorrow
next week (this one can be tricky)
next month

By area:
City or district of a city

And also by:
budget (up to this value)
by hour of the day

Also the ability to click on the button "show events that will happend near me" (i know toolset has the ability to know the user location) on a specific date range. And that this result may be filtered in grid list or map with pins.

I've checked many documentation about the range filters for date.

I'm not a code guru, i know html/css pretty good and some javacript, but i know this requires a bit of php and i was wondering if this makes sense and if all is possible to achieve with Toolset Support.

Thank you for your time.

#1114913

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-09-25 at 09.45.59.png

Hi there

By period of time
Date fields are stored as UNIX timestamps (i.e. numbers) and so any query filters that use these date fields must be formulated such that you are comparing like with like, i.e. you are comparing timestamps with timestamps.

Normally when you insert date filters you might add a BETWEEN comparison where you add filter controls for the 'from' and 'to' dates, and to search for events happening "next month" the user would set the from date as 1 Oct 2018 and the to date as 31 Oct 2018.

When you insert filter controls for a date field the only input type options are a text input or a datepicker. (See the screenshot where I'm inserting the controls for a "Launch date" field with a between comparison.)

If you want the users to instead choose from a series of options ("today", "tomorrow", "next week", "next month") then you would need to choose the text input option and visually hide the text inputs and use JS to add a select dropdown with a series of options which you would then use to populate the hidden text inputs with the required values (UNIX timestamps for the from and to values corresponding to, for example, "next week").

By area
You can filter by distance from a location that a user enters, which is based upon the address field stored for each post (or they can choose their location as the centre of the search).

If you wanted to list all posts from "Chicago" for example, that's not quite the same thing. You would need to actually store "Chicago" as either a custom field or, better, a location taxonomy term. (Better because taxonomies are optimised for queries in a way that custom fields are not.)

And also by:
Up to budget is simple enough, you just insert a filter control for the price field and use a less then comparison instead of equals.

Hour of the day cannot be done based upon the date field stored for the post, because it is impossible to generate a comparison that compares like with like.

You would need to explicitly also store the hour of day (either as a custom field or taxonomy term).

You can add these filters to a single View, and output the View as both a list of results and—at the same time—as markers on a map.

#1114969

Hi Nigel,

Thank you for your time.

If you want the users to instead choose from a series of options ("today", "tomorrow", "next week", "next month") then you would need to choose the text input option and visually hide the text inputs and use JS to add a select dropdown with a series of options which you would then use to populate the hidden text inputs with the required values (UNIX timestamps for the from and to values corresponding to, for example, "next week").

What you're saying is to add an eventlistener that populate hidden fields based on a select change, that's a nice workaround.
I created a pen for this, you can check @ hidden link . So i would have to convert next monday and ('next monday' + 7) in unix time and populate the select option equivalent for next week, is this correct? The same would apply for today, tomorrow and next month.

By area
You can filter by distance from a location that a user enters, which is based upon the address field stored for each post (or they can choose their location as the centre of the search).

If you wanted to list all posts from "Chicago" for example, that's not quite the same thing. You would need to actually store "Chicago" as either a custom field or, better, a location taxonomy term. (Better because taxonomies are optimised for queries in a way that custom fields are not.)

In this case it's not actually city, it would be a google maps auto-complete suggestion field. So for city/area i believe there's nothing that toolset can't do i believe? The google maps field search is already auto-suggest.
But i was thinking about something, if city is not defined as custom field then i would not be be able to create custom evets links for specific cities using the parametric search, correct? Kind of "Events in New York" link.

Hour of the day cannot be done based upon the date field stored for the post, because it is impossible to generate a comparison that compares like with like.

You would need to explicitly also store the hour of day (either as a custom field or taxonomy term).

Hour of the day as a custom field and custom mask is fine, but how would it work since we should be handing as time field. For example:

- search for events that will happen next month from 07:30 to 09:30.
- If i want to add a time range (eg: search for morning which is to from 07:00 to 13:00), they would have to be a date field correct?

How would this values be stored, as integer?

Thanks once again.

#1115710

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Date options
That's the right idea, but don't forget that the timestamps relate to a point in time. There is no timestamp for tomorrow, only an exact time tomorrow. All of these examples involve a between comparison with a From and a To field. So "tomorrow" might be from midnight tonight to midnight tomorrow, for example. Next month would be from 01 Oct 2018 00:00 to 31 Oct 2018 23:59.

By area
Your reasoning is correct.

You might want to automatically add a custom field for the City so that you can use that for queries.

When we interrogate the Google API we store the complete address as formulated by Google as well as the coordinates for the address which are cached, but we discard the other data returned by Google, including the City, State, zip code etc.

I shared a solution with another user about how to extract and store the zip code, and another user added to the thread with a solution to store all of the data, so I think you should be able to use that to get and save the city name:

https://toolset.com/forums/topic/separating-content-from-the-address-field/

hour of the day
Based upon how WP Queries work, and how the date fields are stored, something like "search for events that will happen next month from 07:30 to 09:30" isn't readily possible.

A date filter ("events from next month") would be separate to an hour-of-the-day filter. I think such a filter should work if you store it as a string in 24H format, because you can do string comparisons ("08:59" > "08:01" is true, for example). So store the time of day as a string and add a BETWEEN filter that compares as a string.

#1115768

Hi again Nigel,

Date options

I understand where you getting at. But with javascript i can get 00:00 of a specific day, having the server time as a guide.
Actually this got me wondering about 1 thing that i haven't thought about it which is the recurring events. For example events that happen every sunday.
Anyway the FINISHDATE field should always be present. But i can add an eventlistener with a checkbox labeled "this event will happen in the same day" which will fill the FINISHDATE with the same value as the STARTDATE field.

Recurring Events
I was thinking about this option and all i have to say is that i see no option other than to display only the STARTDATE to the user (with FINISHDATE hidden and filled automatically). But how can i use Toolset to list both (one time event and recurring) using the same STARTDATE field, in the listings search?
I mean, i can't tell Toolset Forms that based on a selected checkbox to set multiple dates (every sunday from now on) in a date field.
This could be achievable with repeating date fields but that doesn't make much sense.

I was thinking about ignoring the datefield and go for specific fields for recurring events, so the company that inserts the event must fill a field "day of the week" for the event. But i think this messes up big time with the search.

Since the default date range filters will be hidden and replaced with javascript select.. i believe i can assign an OR operator to evaluate if the recurring event field is checked , if it is, search for the next day of the week mentioned on that specific field, and return the unix time. And i thought this would be js lightweight...

By area
That's great, so what you're saying is that the user doesn't need to fill the city field.

hour of the day
"Next month" and "07:30-09:30" are 2 separate search fields.
That's great news, with custom mask "##:##"i bet it works great.

Events search from this point on
I know toolset views allows me to query for only future events based on date field (https://toolset.com/documentation/user-guides/date-filters/).
But if it's a recurring event only a script could be able to:

- check what days of the week are selected on a checkbox group
- get the next day (eg: today + 1)
- convert today + 1 to unix timestamp
- insert into the event datefield

Or is there any other way for Toolset to achieve this?

Actually the recurring events part got me wondering of how complex this will be to implement, since for multiple days (events that will happen every monday and thursday) it would have to exist several hidden date fields for it work (and a complex JS calculation on the background).

The problem is that the client is very picky and the plugins available don't really have all the search functionalities, due also to the fact that toolset is expandable while plugins we have to stick to what they develop.

Thanks

#1116207

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screen Shot 2018-09-27 at 10.18.04.png

I don't really have a lot to say about recurring events, they are potentially complicated to implement.

Event plugins, such as the Events Calendar, handle recurring events by creating new event posts for every event occurrence, rather than trying to record all of the dates as fields of a single post, which makes filtering unduly complex.

In the screenshot you can see I'm adding an event which repeats every Thursday.

On saving this single post I can go into the wp_posts table of the database and see that many new event posts are added, one for each Thursday occurrence.

When it comes to building something fairly advanced like an events system, you should consider whether your efforts are better spent on building it from scratch using tools such as ours, or taking a dedicated product designed for the purpose and adapting it to your needs.

#1116540

Thanks Nigel for your time! I believe i will have to check other solutions.