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?

2 Answers 2

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').'" />';
}
1
  • Sorry that's not what I asked. I want to add another input field in the same row. Commented Mar 30, 2017 at 13:03
0

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

1
  • Can you please provide example? What if you are using array format ie. <input name="your_option[second_field]">? Commented Jun 24, 2018 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.