Home Forums Backend Issues (wp-admin) Copy posts to user profiles Reply To: Copy posts to user profiles

  • Unfortunately, there really isn’t a lot of information.

    Basically you need to create a temporary function, what I mean by that is that you create a function that you will remove after your run it once. I usually do this kind of thing on the “init” hook. Also, I do not update anything until I’m sure it’s going to run correctly.

    // add to functions.php
    add_action('init', 'migrate_user_data');
    function migrate_user_data() {
      // I usually set this to only run when I am logged it
      // so that this does not affect the site
      // swap id for your id
      if (!is_user_logged_in() || get_current_user_id() != 1) {
        // not me

    The rest of the function gets complicated and I don’t have specific code. I’ve pretty much explained already what you’ll do in this function.
    1) Do a query to get all of the posts of your post type
    2) Loop over the returned posts
    3) Get the user ID that matches the post by matching something in the post to the user
    4) get the ACF fields that you want to copy from the post
    5) Use update_field() to update the values for the user.Be sure to use the field key and not the field name for each field. Also supply the correct user ID for acf which will be 'user_'.$user_id. update_field('your-field-key, $value, 'user_'.$user_id);