Problem:
I have a Custom Query where I check against a Toolset Date Field in a WP_Query.
Example:
$today = date( 'Y-m-d', strtotime('today') ); 'meta_query' => array( array( 'key' => 'wpcf-tour-date', 'value' => $today, 'compare' => '>=', 'type' => 'DATE', ), ),
It does not return anythign, even if there are fields with values.
What's wrong?
Solution:
Our Dates Field is a Timestamp.
As such, it's a numeric value, not a date format.
The 'type' DATE works with the 'compare' value BETWEEN only if the date is stored at the format YYYY-MM-DD and tested with this format.
And our Date Field is not storing it in this format but in a simple timestamp format.
The easiest solution is to compare as a NUMERIC value as that is what Toolset stores for the Date Fields.
Relevant Documentation:
https://toolset.com/forums/topic/filter-only-future-posts-in-wp_query-by-custom-date-field/#post-547754
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
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 7 years, 4 months ago.
Assisted by: Beda.
The forum ‘Types Community Support’ is closed to new topics and replies.