0

I've created a CPT to store a show calendar.
An ACF field calendar has been created to store places and dates of the shows. It is a repeater composed by 2 subfields: date (type=date) and city (type=select).

When I'm trying to copy the "calendar" field from one post to another, using
update_field( 'calendar', get_field( 'calendar', $id_post_origin ), $id_post_destination );
the dates are corrupted.

I've tried to run a delete_field() before but the result isn't better.

e.g. if my original post is:
0 => array (size=2) 'city' => string 'Vesoul' (length=6) 'date' => string '02/09/2019' (length=10)
the destination post will be after copying:
0 => array (size=2) 'city' => string 'Vesoul' (length=6) 'date' => string '09/02/2019' (length=10)

Is it possible to specify a date format? To duplicate a field without modifying it?

Thank you

Patrick
  • 189
  • 1
  • 11

1 Answers1

1

As specified by Kenny from ACF support,

The get_field() function contains a formatting parameter that you set to false in order to return the raw database value. In the case of the date field, the unformated string would be in YYYYMMD format.

The ACF get_field() manual describes this $format_value parameter and provide an example to "Get a value without formatting".

In my case, the solution was to edit the get_field() call like this:
$dates = get_field( 'calendar', $id_post_origin, false ); // false to retrieve raw data update_field( 'calendar', $dates, $id_post_destination );

Patrick
  • 189
  • 1
  • 11