I have been testing with the following events and dates…
Test 1
23/05/2015 – 23/05/2015
25/05/2015 – 29/05/2015
Test 2
24/05/2015 – 24/05/2015
The trouble is that the following code is returning Test 1 and Test 2 for the date range of 24/05/2015 – 24/05/2015 when only Test 2 should be returned
<?php
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'event_dates_%", "meta_key LIKE 'event_dates_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array (
'post_type' => 'event',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'event_dates_%_start_date',
'compare' => '<=',
'value' => '20150524',
),
array(
'key' => 'event_dates_%_end_date',
'compare' => '>=',
'value' => '20150524',
)
),
);
$the_query = new WP_Query( $args );
?>
Thanks but it looks like its the query that gets generated thats the problem, could be an issue with the JOIN. I think its gonna have to be recoded/build again
Thanks
Thanks for your reply. Sorry that was a typo in the supplied dates
Example Dates
13/05/2015 – 14/05/2015
16/05/2015 – 24/05/2015
I have been doing some test using the following ranges
TESTS
1 = 13/05/2015 – 14/05/2015 – Should return results
2 = 15/05/2015 – 15/05/2015 – Should not return results
3 = 18/05/2015 – 22/05/2015 – Should return results
4 = 18/05/2015 – 25/05/2015 – Should return results (because the search start date is after the event start date)
Test 4 is causing problems.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.