• Hi guys i’m continue to try in a task but without result, i have in my function.php child theme adding some user meta and works no problem, but i need to display this data only inside a user profile with a specific user role named “rivenditore” and if is instead the role is “installatori” i need to display another table how can i do?

    Thanks a lot

    // USERMETA

    add_action( ‘show_user_profile’, ‘stel_extra_field_meta’ );
    add_action( ‘edit_user_profile’, ‘stel_extra_field_meta’ );

    function stel_extra_field_meta( $user ) {
    ?>

    <h3>Dati Rivenditore</h3>

    <table class=”form-table”>
    <tr>
    <th><label for=”location”>Location</label></th>
    <td><input type=”text” name=”location” value=”<?php echo esc_attr(get_the_author_meta( ‘location’, $user->ID )); ?>” class=”regular-text” /></td>
    </tr>
    <tr>
    <th><label for=”regione”>Regione</label></th>
    <td><input type=”text” name=”regione” value=”<?php echo esc_attr(get_the_author_meta( ‘regione’, $user->ID )); ?>” class=”regular-text” /></td>
    </tr>
    <tr>
    <th><label for=”tipo_rivenditore”>Tipo di Rivenditore</label></th>
    <td><input type=”text” name=”tipo_rivenditore” value=”<?php echo esc_attr(get_the_author_meta( ‘tipo_rivenditore’, $user->ID )); ?>” class=”regular-text” /></td>
    </tr>

    <tr>
    <th><label for=”service_type”>Servizio Scelto</label></th>
    <?php $value = esc_attr(get_the_author_meta( ‘service_type’, $user->ID )); $service_type = preg_replace(‘/\|.*/’, ”, $value); ?>
    <td><input type=”text” name=”service_type” value=”<?php echo $service_type; ?>” class=”regular-text” /></td>
    </tr>

    <tr>
    <th><label for=”phone”>Phone</label></th>
    <td><input type=”text” name=”phone” value=”<?php echo esc_attr(get_the_author_meta( ‘phone’, $user->ID )); ?>” class=”regular-text” /></td>
    </tr>
    </table>
    <?php
    };

    get_the_author_meta( $field, $userID );

    update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );

    add_action( ‘personal_options_update’, ‘stel_save_extra_field_meta’ );
    add_action( ‘edit_user_profile_update’, ‘stel_save_extra_field_meta’ );

    function stel_save_extra_field_meta( $user_id )
    {
    update_user_meta( $user_id,’location’, $_POST[‘location’] );
    update_user_meta( $user_id,’service_type’, $_POST[‘service_type’] );
    update_user_meta( $user_id,’phone’, $_POST[‘phone’] );
    update_user_meta( $user_id,’regione’, $_POST[‘regione’] );
    update_user_meta( $user_id,’tipo_rivenditore’, $_POST[‘tipo_rivenditore’] );
    }

The topic ‘user meta by user role’ is closed to new replies.