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 have one option on a settings page that can have between 1 and 5 values. I have a basic understanding on how to set up single value settings using the Settings API, but how do I go about generating the markup etc. for the setting with a variable number of values?

share|improve this question
Please could the person who voted this question down try and be constructive by leaving a comment saying why. I see nothing wrong with it myself, but would appreciate any input on how to improve it. – ProfK Nov 30 '11 at 4:39
up vote 3 down vote accepted

If you are using the Settings API correctly, you should be using the add_settings_field function. The 3rd argument in this function is for the callback function that will generate the HTML for the form field for the individual setting. The Codex states:

Function that fills the field with the desired inputs as part of the larger form. Name and id of the input should match the $id given to this function. The function should echo its output.

In this callback function, you just write your HTML, just like you would if WordPress was not involved. As such, you can setup radiobuttons, a select field, multi-select, etc.

As an example, let's say that you use add_settings_field as such:

    'My Setting Name',

In this snippet, the callback function named "my_setting_callback_function" will generate the HTML for the setting. You can then do something like:

function my_setting_callback_function() {
    <select name="my_setting_name" id="my_setting_name">
        <option value="1">Enabled</option>
        <option value="0">Disabled</option>

As you can see, this function generates the different possible values for this setting.

I highly encourage reading this part of the Codex: http://codex.wordpress.org/Settings_API. It does a nice job explaining the Settings API and the example does a good job illustrating how to use it. I find that the API is a bit convoluted; however, it does what it says it should do, so with a little discipline and careful checking, it should work quite well for you.

Good luck!

share|improve this answer

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.