Problem Solved but solution not reusable.
I’d like some advice or a solution to assign the same meta_key to each datetime generated.
Based from this answer : to assign variables to each datetime from foreach loop I do that (but I think it’s a bad idea to change the name of the array keys using the is_int() function to target the key integers):
- create an array ($events_meta)
- Inside a foreach loop, call the dates of DatePeriod
My solution is only usable because I only use is_int for the ‘timestamps_between’ meta_key.
$start = $beginOfDayObject;
$interval = new DateInterval('P1D');
$end = $excludeObject;
$period = new DatePeriod($start, $interval, $end);
$events_meta = array();
foreach ($period as $date) {
$events_meta[] = $periodtotime."\n";
}
each new meta_key will be read by this foreach loop:
(The condition using is_int() allow to replace all keys integer by the meta_key.)
foreach ( $events_meta as $key => $value ) {
if(is_int($key) ) $key ='timestamps_between';
add_post_meta( $post->ID, $key, $value );
}