Support

Account

Home Forums Front-end Issues Add Custom User Meta to ACF Form Fields

Solved

Add Custom User Meta to ACF Form Fields

  • I’ve come across a unique problem where I would like some help with a solution.

    I created a Registration Form using Gravity Forms that is on the Main Site within a Multisite Network. This form creates a new blog/site and Custom User Meta data when submitted.

    I want to convert the newly created user meta into post meta for specific fields within ACF. The difficulty (I think) is automatically updating the field values when the new blog/site is created.

    I am already hooking into the wpmu_new_blog action to create pages and update blog options when a new blog/site is created, and I attempted to use the acf function update_field() to update a acf field, but it doesn’t seem to work.

    Any ideas?

  • I found a solution to my problem. I ended up using the wpmu_new_blog action hook to update the post meta when a new blog is created.

    Here is a basic idea of the code used:

    add_action('wpmu_new_blog', 'katart_update_new_blog', 10, 2);
    function katart_update_new_blog($blog_id,$user_id) {
       switch_to_blog($blog_id);
    
       $admin = get_userdata( $user_id );
    
       update_post_meta( 4, 'custom_post_meta', $admin->custom_user_meta );
    
       restore_current_blog();
    }

    This was a unique situation where I know the post ID. I hope this helps someone.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Add Custom User Meta to ACF Form Fields’ is closed to new replies.