I am having a search kind for leases that search areas obtainable in keeping with a date vary.
For now, I retailer all reserved dates for every posts as post_meta. For exemple ;
post_id: 231 post_meta : location_reservation_start : 2022-09-02
post_id: 231 post_meta : location_reservation_end : 2022-09-08
post_id: 231 post_meta : location_reservation_start : 2022-10-02
post_id: 231 post_meta : location_reservation_end : 2022-09-02
(a number of meta_key for a similar put up)
There’s the question :
$start_date = $dates[0] ;
$end_date = $dates[1] ;
$date_query[] = array(
'key' => 'location_reservation_start',
'worth' => array($start_date , $end_date ) ,
'examine' => 'NOT BETWEEN',
'kind' => 'DATE'
) ;
$date_query[] = array(
'key' => 'location_reservation_end',
'worth' => array($start_date , $end_date ) ,
'examine' => 'NOT BETWEEN',
'kind' => 'DATE'
) ;
array_push($meta_query, $date_query );
This code work if there’s just one post_meta for put up. So long as the put up have a number of identical meta_key, the NOT BETWEEN would not appear to work.
There’s a strategy to make it work like that or ought to I retailer the reservation dates in a post_meta serialized as an array?
Thanks