0

I want to add a third column consisting of an input textfield using the Settings API. Is this possible?

function print_custom_field()
{
    $value = get_option( 'my_first_field', '' );
   $value_second = get_option( 'my_second_field', '' );
    echo '<input type="text" id="my_first_field" name="my_first_field" value="' . $value . '" />';
echo '<input type="text" id="my_second_field" name="my_second_field" value="' . $value_second . '" />';
}

add_filter('admin_init', 'register_fields');

EDIT: I tried this code and Wordpress doesn't save the values of the second input field. Only the value of the first input field gets saved. How can I show another text input in the same row?

0

From the settings API,

add_settings_field(
    'my_first_field-id',
    'This is the setting title',
    'myprefix_setting_callback_function',
    'general',
    'myprefix_settings-section-name',
    array( 'label_for' => 'my_first_field-id' )
);
myprefix_setting_callback_function(){

  echo '<input type="text" name="my_first_field" value="'.get_option('my_first_field').'" />';
}
  • Sorry that's not what I asked. I want to add another input field in the same row. – input Mar 30 '17 at 13:03
0

All I needed to do was register_setting for the second input.

  • Can you please provide example? What if you are using array format ie. <input name="your_option[second_field]">? – Josh Jun 24 '18 at 4:27

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.