Skip Navigation

[Resolved] adding custom fields in types cpt while new user registration

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#924653

i am trying to create a new cpt automaticly while a new user are registered
i found some codes and finally used this:

* Create new custom post type post on new user registration
 */
add_action( 'user_register', 'beor_cpt', 10, 1 );
function beor_cpt( $user_id )
{
    // Get user info
    $user_info = get_userdata( $user_id );

    // Create a new post
    $user_post = array(
        'post_title'   => $user_info->nickname,
        'post_content' => $user_info->description,
		'post_status'   => 'publish',
        'post_type'    => 'beor-user', // <- change to your cpt
		'post_tehudat-zehut-family-member' =>$_POST['wpcf-tehudat-zehut-user']
    );
    // Insert the post into the database
    $post_id = wp_insert_post( $user_post );

    // Add custom company info as custom fields
    add_post_meta( $post_id, 'wpcf-tehudat-zehut-family-member', $_POST['wpcf-tehudat-zehut-user'] );
   add_post_meta( $post_id, 'wpcf-family-member-email',  $user_info->user_email );
}

Now the email goes perfect to the new 'beor-user' cpt but the 'tehudat-zehut-family-member' doesnt work.
Any ideas?

#924900

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Meirk,

Thank you for contacting our support forum.

You're saying that when the post is created the custom field information isn't populating with the values correct?

Please let me know.

Thanks,
Shane

#947726

bsd

Yes, you explained it correctly

#948408

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Meir,

Thank you for the explanation.

Would you mind providing me with admin access to this site so that I can test this our first hand?

Thanks,
Shane