ACF – get posts with repeated start and ending date
-
Im running a travelling-site with journeys which have a start and ending date. Now these journeys can be several times a year.
Now I have a single-post with three repeated start and ending dates:
01.03.2015 - 14.03.2015 01.04.2015 - 14.04.2015 01.05.2015 - 14.05.2015
I want to show my post with its start and ending dates contained in the search date range.
Searching 01.03.2015 – 01.04.2015 should return one result.
Searching 01.06.2015 – 01.07.2015 should return no results.$reisen_query_args = array( 'post_type' => 'reisen', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'reisezeiten_%_start', 'compare' => '>=', 'value' => $startdate, 'type' => 'DATE' ), array( 'key' => 'reisezeiten_%_end', 'compare' => '<=', 'value' => $enddate, 'type' => 'DATE' ) )
This works half-way and I cant figure it out why:
if the search range is 01.03.2015 – 10.03.2015 the post doesn’t show up which is correct
BUT
if the range is 05.03.2015 – 16.03.2015 the post shows up which is WRONG because the search starting date must be 01.03.2015 or before to return results.
AND
this only happens when Im having repeated fields. As long theres only one date stored 01.03.2015 – 14.03.2015 the query behaves as desired.
Could someone pls help me with this? I’m searching for weeks now to get this done.
This is how my query looks like:
SELECT SQL_CALC_FOUND_ROWS wp410_posts.ID FROM wp410_posts INNER JOIN wp410_term_relationships ON (wp410_posts.ID = wp410_term_relationships.object_id) INNER JOIN wp410_postmeta ON ( wp410_posts.ID = wp410_postmeta.post_id ) INNER JOIN wp410_postmeta AS mt1 ON ( wp410_posts.ID = mt1.post_id ) WHERE 1=1 AND ( wp410_term_relationships.term_taxonomy_id IN (29) ) AND wp410_posts.post_type = 'reisen' AND ((wp410_posts.post_status = 'publish')) AND ( ( wp410_postmeta.meta_key LIKE 'reisezeiten_%_start' AND CAST(wp410_postmeta.meta_value AS DATE) >= '2015-03-02' ) AND ( mt1.meta_key LIKE 'reisezeiten_%_end' AND CAST(mt1.meta_value AS DATE) <= '2015-03-14' ) ) GROUP BY wp410_posts.ID ORDER BY wp410_posts.menu_order ASC LIMIT 0, 6
- The topic ‘ACF – get posts with repeated start and ending date’ is closed to new replies.