Values not storing or showing using Settings API
-
I’ve been working with the Settings API for a few days, wrapping my head around it. It’s really great but I’m having a minor issue. I’m running into problems with the newly added settings field populating with a value. It returns the “Settings saved” but the value is not stored in the DB.
Can anyone help with this. I know there is an error here but I just don’t see it.
`add_action(‘admin_menu’, ‘tvst_add_pages’);
add_action(‘admin_init’, ‘tvst_admin_init’);function tvst_add_pages() {
add_posts_page( ‘Add New Battle’, ‘Add New Battle’, ‘publish_posts’, ‘tvst-posts’, ‘tvst_posts’);
};function tvst_admin_init(){
register_setting( ‘tvst_options’, ‘tvst_options’ );
add_settings_section(‘tvst_settings’, ‘Table VS Table’, ‘tvst_section_text’, ‘writing’);
add_settings_field(‘tvst_cell_count’, ‘Number of comparisons’, ‘tvst_cell_count’, ‘writing’, ‘tvst_settings’);
};function tvst_posts(){
if (!current_user_can(‘publish_posts’)) {
wp_die( __(‘You do not have sufficient permissions to access this page.’) );
}
echo ‘<div class=”wrap”>’;
echo ‘<p>Here is where the form would go if I actually had options.</p>’;
echo ‘</div>’;};
function tvst_section_text() {
echo “<p>” . esc_attr_e(“Enter the number of things you’d like to compare, as well as the category you’d like to use to display the tables below.”) . “</p>”;
};function tvst_cell_count() {
$option = get_option(‘tvst_options’);
echo ‘<input type=”text” id=”tvst_text_string” name=”tvst_options” value=”‘ . $option[‘tvst_cell_count’] . ‘” size=”1″ maxlength=”2″ />’;
};
function tvst_options_validate($input) {
$newinput[‘text_string’] = trim($input[‘text_string’]);
if(!preg_match(‘[0-9]{2}’, $newinput[‘text_string’])) {
$newinput[‘text_string’] = ”;
}
return $newinput;
};’
- The topic ‘Values not storing or showing using Settings API’ is closed to new replies.