Support

Account

Home Forums General Issues Programmatic duplication Reply To: Programmatic duplication

  • I’m not 100% certain, didn’t dig that far, but I think the function you’re calling acf_duplicate_fields(); is an internal ACF function that’s used to either duplicate a field group or to duplicated fields inside a field group and not to duplicate the meta values associated with a post.

    If you need to manually duplicate all of the post meta attached to a post then use.

    $meta = get_post_meta($post_id);

    when used without a meta_key this returns an array of all meta values attached to a post. For more information see the codex here https://developer.wordpress.org/reference/functions/get_post_meta/

    Then you’d need to loop through this array and use add_post_meta() for each key in the array to add it to the new post. As far as I know there isn’t a function to add all the meta values in one go.