For a custom plugin with add start and end date of event/post, I must generate several datetime with the same meta key to compare the period of event with the period of weeks. I my case I'm obliged to compare each day date of event with these of period because the 'key'=>
of meta_query can't be a array.
The user will have the choice with current week, week +1 and week+ 2 and 3.
I created a script to generate all days between start and end of event. Depending on my custom plugin script to add/update several _post_meta(), I include each meta key inside an array.
The period event is from 12 to 28 September : my script generate these date :
2023-09-12 00:00:00
2023-09-13 00:00:00
2023-09-14 00:00:00
2023-09-15 00:00:00
2023-09-16 00:00:00
2023-09-17 00:00:00
2023-09-18 00:00:00
2023-09-19 00:00:00
2023-09-20 00:00:00
2023-09-21 00:00:00
2023-09-22 00:00:00
2023-09-23 00:00:00
2023-09-24 00:00:00
2023-09-25 00:00:00
2023-09-26 00:00:00
2023-09-27 00:00:00
2023-09-28 23:59:59
Each date ($date) is converted into a datetime to obtain a timestamp.
In meta_query
these dates are compared with those of the selected week :
from 2023-09-18 00:00:00 to 2023-09-24 00:00:00
How can I output these datetime allocating a variable to each to obtain as many times this variable as there are dates generated
$events_meta['timestamps_between'] = strtotime($date);
foreach ($period as $date) {
$events_meta['timestamps_between'] .= strtotime($date);
}
My script call many meta_key
and I called them inside this foerreach :
foreach ( $events_meta as $key => $value ) {
add_post_meta( $post->ID, $key, $value );
//if($key = 'timestamps_between'){
//print_r($key .' and '. $value);
//}
}