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;