I'm adding a settings section to a theme that will allow the user to enter testimonials which will be randomly displayed on the site. Each testimonial has 2 fields, author and testimonial, I've registered my settings as below:

register_setting( 'settings-website', 'option_testimonials', 'save_testimonials' );

And I want to store an array within that option like this:

array(3) {
  array(2) {
    string(8) "Person A"
    string(14) "Great website!"
  array(2) {
    string(8) "Person B"
    string(15) "Excellent work!"
  array(2) {
    string(8) "Person C"
    string(10) "Brilliant!"

My options form looks like this:

$testimonials = get_option('option_testimonials');
if( !is_array($testimonials) )
    $testimonials = array();
<div class="wrap">
<form method="post" action="options.php">
    <?php settings_fields( 'ddtheme-settings-testimonials' ); ?>
    <table class="form-table">
        <?php foreach( $testimonials as $testimonial ) { ?>
        <tr valign="top">
        <th scope="row">Testimonial</th>
        <?php } ?>
        <tr valign="top">
        <th scope="row">New testimonial</th>
            <input type="text" name="author" style="width: 400px;" /><br/>
            <textarea name="testimonial" style="width: 400px;"></textarea>
    <p class="submit">
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />

So I thought I could grab the input from the author and testimonial fields inside save_testimonials, combine them into an array and append that to the existing array and save but the $_POST and $_REQUEST are both empty inside that callback.

How can I do this?

1 Answer 1


You'd probably be best to use add_settings_field and add_settings_section...

But in any case, save_testimonials is your validation / save callback function. It is given the data from the form and its job is to check it and then return the validated options. You shouldn't be touching $_POST or $_REQUEST - that's the point of the settings api.


     //Validate the $array_of_data_from_form 

     $validated=array()//Your settings array after validation

    return $validated;

But it will only recieve data with input name option_testimonials as registered in your register_setting. So your input fields will need names like option_testimonials[testimonial] and option_testimonials[author].

Best practise dictates that you should prefix your option names (option_testimonials is a bit too generic).

As far tutorials go concerning the settings API you can't go far wrong with this post.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.