WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 wrote a simple test code for testing saving data using Setting API, but it doesn't seem to work. it realy driving me crazy. Please help me point out the problem, thanks!

function test_add_options_page() {
        'Test Save Option',
        'Test Save',
add_action('admin_menu', 'test_add_options_page');

function test_save_page() {
        <form action="options.php" method="post">


function test_add_settings() {
        'Section 1',

        'Field Title',

    register_setting('testpage', 'testpage');
add_action('admin_init', 'test_add_settings');

function output_section_desc() {
    echo 'Section Description...';

function add_field_callback() {
    echo '<input type="test" id="field_id" />';
share|improve this question
up vote 1 down vote accepted

First off, your input field is missing a name attribute.
The id attribute is a unique identifier, mainly used by the visitor's browser, to target elements via CSS or JS.
The name attribute is an identifier for form elements to be used in the POST or GET request on form submission.

Also, test is not a valid input type.

So far, that's generic and not at all specific to the Settings API.

Your callback should hence look like this:

function add_field_callback() {
    echo '<input type="text" id="field_id" name="testpage[\'field_id\']"/>';

The Settings API saves options in option groups. You defined your group to be called 'testpage'. Hence to retrieve the saved value, you'd do something along the lines of:

$testpage_values = get_option( 'testpage' );
$field_value = isset( $testpage_values['field_id'] ) ? $testpage_values['field_id'] : 'Not set.';
echo $field_value;
share|improve this answer
Got it. thanks Pille, for the quick answer, it's clear and detailed. – user34894 Jul 4 '13 at 9:30

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.