Support

Account

Home Forums Backend Issues (wp-admin) How to update postmeta with ACF? Reply To: How to update postmeta with ACF?

  • 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);
            }
        }
    }