Support

Account

Home Forums Front-end Issues Generating usermeta field with PHP

Helping

Generating usermeta field with PHP

  • Hello,
    I created some extra user field with the module, setting up the location at “User role is equal to all”. It works fine with the standard WordPress registration and update forms but I would like to use it in a custom registration page that I created with PHP.
    It’s a very simple form, I’m using the wp_create_user() function with some $_POST variables and I would like to know if I also could create the ACF new meta fields this way.
    I know there is an add_user_meta() function in WordPress but the ACF plugin is creating two rows each time in the usermeta database, a “my_field” row with the value of the field and a “_my_field” row with a generated “field_randomnumber” value. Is there an ACF function that can create those two rows with a $_POST value ?

    Thanks

  • Ok so here’s what I did, since the group field and the fields are created in the wp_posts table, I just checked the group ID and then proceed to list any field attached to it in a loop and then doing two add_user_meta() for each field :

    $get_fields = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'posts WHERE post_parent ="id_of_the_group"');
    foreach ( $get_fields as $field ) {
    switch ($field->post_excerpt) {
       case 'my_acf_field_name' : 
    	add_user_meta($user_id, $field->post_excerpt, $_POST['my_value']);
            add_user_meta($user_id, '_'.$field->post_excerpt, $field->post_name);
    	break;
       case '...

    I know this is really really dirty coding but sadly this is the best I can do.

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

You must be logged in to reply to this topic.