0

I try to customize users profile using this code (from this tutorial) :

<?php function extra_user_profile_fields( $user ) { ?>

  <h3>Autres</h3>
  <table class="form-table">
    <tbody>
      <tr>
        <th>Entreprise</th>
        <td><input class="regular-text" id="entreprise" type="text" name="entreprise" value="<?php echo esc_attr( get_the_author_meta( 'entreprise', $user->ID ) ); ?>" /></td>
      </tr>
      <tr>
        <th>OS</th>
        <td><input class="regular-text" id="os" type="text" name="os" value="<?php echo esc_attr( get_the_author_meta( 'os', $user->ID ) ); ?>" /></td>
      </tr>
    </tbody>
  </table>

<?php }
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function save_extra_user_profile_fields( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) ) { 
        return false; 
    }
    update_user_meta( $user_id, 'entreprise', $_POST['entreprise'] );
    update_user_meta( $user_id, 'os', $_POST['os'] );
}
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' ); ?>

I saw a strange thing when I tried to add custom user meta data into Wordpress; I save custom data on a user's profile, the data is saved on the page and I can see it even if I reload it, but when I take a look in the database, the table _usermeta hasn't changed at all; the custom data is nowhere ! I tried other tutorials, there isn't any php problem, but it doesn't change.

It's driving me mad, where are the data stored then ?

0

It should be stored in the wp_usermeta table under the entreprise and os user meta keys.

You should consider using prefix on your custom meta keys, to avoid name collison. Example:

kerzzy_entreprise 
kerzzy_os

It should show up with:

SELECT * FROM `wp_usermeta` WHERE `meta_key` = 'entreprise'

in your MySQL administration tool, e.g. PHPMyAdmin.

... and make sure you're in the correct database ;-)

  • I made a request into phpMyAdmin then I saw them. The next lines (after ~30) into the main request were only hidden, that's why I didn't saw them (yeah phpMyAdmin). One reason why command line is better.. I was searching too far for this silly tiny detail. Thank you to have opened my blind eyes and for your quick answer ^^ – Kerzzy Jul 9 '15 at 12:16
  • glad to hear it worked out for you @Kerzzy – birgire Jul 9 '15 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.