WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a plugin to edit my profile page.

How can I save data of an input field to the database and then display it?

This is my code. The first part is the display in HTML:

<form method ="POST">
    <div id= 'dynamic_input_groups'>
        <input type='text' name='group[]' id='group[]' class="regular-text"
            value="<?php echo esc_attr( get_the_author_meta( 'group', $user->ID ) ); ?>" />

        <input type="button" class="button-primary" value="Add"

And the second part is the script for the button click and the input field:

var counter = 1;
var limit = 15;
function addInput(divName) {
    if (counter == limit) {
        alert("You have reached the limit of adding " + counter + " inputs");
    } else {
        var newdiv = document.createElement('div');
        newdiv.innerHTML = " <br><input type='text' name='group[]'' class='regular-text'>";

And the final part saves the data to the database:

update_usermeta( $user_id, 'group', $_POST['group'] );
share|improve this question
up vote 1 down vote accepted

Don't use update_usermeta, it is deprecated, update_user_meta is the one to use.

You get the previously saved value out with get_user_meta.

<input type='text' name='group[]' id='group[]' class="regular-text"
    value="<?php echo esc_attr( get_user_meta( $user->ID, 'group', true ) ); ?>" />
share|improve this answer
thank you very much dalbaeb ^_^ – user2006362 Apr 25 '13 at 17:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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