Home › Forums › Calendar Products › Events Calendar PRO › Problems to compare start and end date in wp_query
- This topic has 3 replies, 4 voices, and was last updated 9 years, 5 months ago by
quesada.
-
AuthorPosts
-
November 10, 2016 at 2:24 am #1190191
quesada
ParticipantHello,
i need to let my visitor choose a start date and a end date to filter the events.
So i use wp_query, all work fine when i choose only a start date or a and date, see the query below :
When user choose a start date :
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
‘eventDisplay’=>’custom’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventStartDate’,
‘value’ => $date_evenement_debut,
‘compare’ => ‘>=’,
‘type’ => ‘DATE’
)
)
When user choose a end date :
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
‘eventDisplay’=>’custom’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventEndDate’,
‘value’ => $date_evenement_fin,
‘compare’ => ‘<=’,
‘type’ => ‘DATE’
),
)So i tested this request to compare 2 dates with the 2 dates of the events :
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
‘eventDisplay’=>’custom’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventStartDate’,
‘value’ => $date_evenement_debut,
‘compare’ => ‘>=’,
‘type’ => ‘DATE’
),
array(
‘key’ => ‘_EventEndDate’,
‘value’ => $date_evenement_fin,
‘compare’ => ‘<=’,
‘type’ => ‘DATE’
)
)
But it’s not working, i search on multiples forums and some users solve this problem using date on format NUMERIC like this :
$date_event_debut and $date_event_fin is on format YYYYMMDD.
But it’s not working.‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => -1,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
‘eventDisplay’=>’custom’,
‘meta_query’ => array(
array(
‘key’ => ‘_EventStartDate’,
‘value’ => array($date_event_debut,$date_event_fin),
‘compare’ => ‘BETWEEN’,
‘type’ => ‘DATE’
),
),
Do you have any possible solutions ?
Thank you to bring me your light.November 10, 2016 at 2:58 pm #1190659Andras
KeymasterSalut Quesada,
Thanks for using our plugins and welcome to the forums! I’m sorry you are having this issue.
What might cause this is that the _EventStartDate and _EventEndDate are saved in this format:
2016-09-29 17:00:00
If you haven’t checked this article, then it might be of help:
https://codex.wordpress.org/Class_Reference/WP_Query
It has this note in it:
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.
So you might need to do it a bit differently. Maybe DATETIME.
Let me know if that helps.
Cheers,
AndrasDecember 2, 2016 at 8:35 am #1200897Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Problems to compare start and end date in wp_query’ is closed to new replies.
