Skip Navigation

[Resolved] Date search by Date Field

This thread is resolved. Here is a description of the problem and solution.

Problem:
I have a Field where I store a date (Toolset Date Field) and want to filter a View by values of that Date Field.
When I try to add Query Filters by DATE it doesn't seem to work fine.
How should I go about?

Solution:
You should use a NUMBER option instead:

This is because of the Date Fields of Toolset return in fact numbers (timestamps).

Relevant Documentation:
https://toolset.com/documentation/user-guides/date-filters/

This support ticket is created 5 years, 5 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)

This topic contains 2 replies, has 2 voices.

Last updated by DavidW2160 5 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#1262801

I am trying to: create a view to select listings between two dates. I started with the classifieds framework site, then added a "start date" and "end date" (type DATE). I modified the "Listings on a map" view to select a date, and configured the date selection as follows:

Select items with field:
Start Date is a DATE greater than or equal URL_PARAM(wpv-wpcf-start-date)
AND
End Date is a DATE lower than or equal URL_PARAM(wpv-wpcf-start-date)
Link to a page where the issue can be seen:

The filter itself looks like this:
<div class="form-group">
<label>[wpml-string context="wpv-views"]Target Date[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-start-date" type="date" default_date="today()" url_param="wpv-wpcf-start-date"]
</div>

I expected to see: Visiting the "Listings on a map" page, I excepted to be able to select a date within the listing date range (June 8 to June 10).

Instead, I got: nothing. I see the two listings if I delete the "target date", but any other date selection fails to display either listing.

#1263037

You should use a NUMBER option instead:
https://toolset.com/documentation/user-guides/date-filters/

This is because of the Date Fields of Toolset return in fact numbers (timestamps).

It's explained here as well: https://toolset.com/documentation/user-guides/date-filters/
Also, your filter misses the second (end date) input.

Please create the filters only using the GUI, not altering them manually if possible. That should insert a begin and an end date selector for the date filter in the search and pagination section of the View.

Also, a Filter that does filter by date either greater or lower than today will simply show all posts, it would not make sense to have such filter - once triggered it'll just display the same posts as without filter.

I think you want to filter between a start and an end date, pickable by the user on the front end?
Then I'd suggest deleting the current Query Filter and HTML Front end filter, save the view, and after reloading it, insert the Filter in the Search and Pagination section with the "New Filter" button

There choose your date field you want to use, and then choose to filter "Between" - that will automatically produce all options as required

#1263271

My issue is resolved now. Thank you!