WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
  1. I'm trying to save an array to get_options in wordpress, I'm aware that I don't have to serialize the array due to get_options doing that.

  2. At the moment I don't get any success of failed message upon hitting the submit button.

  3. Am I adding the input data correctly to the database using get_options and update_options. If not how can my code be tweaked to accomplish this.

    add_action('admin_menu', 'dw_quotes_create_menu');

    function dw_quotes_create_menu() {
        //create custom top-level menu
        add_menu_page('Quotes Settings', 'Quotes Styling', 'manage_options', 'dw_quotes', 'dw_styling_quotes_settings');
        //generating the random quote
    function dw_get_random_quote() {
    function validate_dw_quote() {
        //validation here
        if (isset($_POST['submit'] ) ) {
            //checking that $_POST['adding_quote'] is set
            if( isset( $_POST['adding_quote'] ) ) {
                //retrieve the stored values
                if( get_option( 'list_of_quotes' ) )
                    $list_of_quotes = get_option('list_of_quotes');
                    $list_of_quotes = array();
                //add the new quote to the end of the array 
                $list_of_quotes[] = $_POST['adding_quote'];
                //store the updated quote
                if ( update_option( 'list_of_quotes', $list_of_quotes ) ) {
                    echo "Success your quote was added!";
                } else {
                    echo "Failed to add quote!";
        //styling the admin menu
    function dw_styling_quotes_settings() { ?>
        <h2>Quote Setting</h2>
        <form action="admin.php?page=dw_quotes" method="post">
        <label for="add">Enter your quote</label>
        <input type="textarea"  name="adding_quote" />
        <input type="submit" name="submit" value="add the new quote" />
        <?php //test the output 
share|improve this question
where do you call validate_dw_quote? – Milo Apr 15 '14 at 0:59
Put die; after your //store the updated quote if/else block. Do you see the message now? – s_ha_dum Apr 15 '14 at 1:09
up vote 0 down vote accepted

In order for it to save the data you need to hook your validate_dw_quote() onto to an action, such as admin_init or init.

add_action('admin_init', 'validate_dw_quote'); 
share|improve this answer
Thanks :D I just completely forgot to add that bit. – Dannyw24 Apr 15 '14 at 20:22

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.