Hello!
I am deeply appreciative of ACF. ACF is my favorite plugin.
I have a worry about updating postmeta.
First I set a ACF date item with saving default “yymmdd”.
But now I want to use as MySQL date format “yy-mm-dd”, so I am trying to update that format.
I think I should use ACF update function to update postmeta manually, but I don’t know which function to be used.
Is this code OK?
function update_acf_manually() {
var_dump('update_acf_manually');
$args = array(
'orderby' => array('ID' => 'ASC'),
'post_type' => 'member',
'posts_per_page' => '-1',
);
foreach (get_posts($args) as $post) {
$pm = get_post_meta($post->ID, 'join_date', true);
$Y = substr($pm, 0, 4);
$m = substr($pm, 4, 2);
$d = substr($pm, 6, 2);
if ($Y && $m && $d) {
var_dump("$Y-$m-$d");
$pm = "$Y-$m-$d";
//update_postmeta($post->ID, $pm);
}
}
}
Thanks!
I think I have to use update_field();
function update_acf_manually() {
var_dump('update_acf_manually');
$args = array(
'orderby' => array('ID' => 'ASC'),
'post_type' => 'member',
'posts_per_page' => '-1',
);
foreach (get_posts($args) as $post) {
$pm = get_post_meta($post->ID, 'join_date', true);
$Y = substr($pm, 0, 4);
$m = substr($pm, 4, 2);
$d = substr($pm, 6, 2);
if ($Y && $m && $d) {
var_dump("$Y-$m-$d");
$pm = "$Y-$m-$d";
update_field('join_date', $pm, $post->ID);
}
}
}