Title: Set List options dynamically?
Last modified: August 24, 2016

---

# Set List options dynamically?

 *  Resolved [johnchanmk](https://wordpress.org/support/users/johnchanmk/)
 * (@johnchanmk)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/)
 * I am trying to add options at a list dropdown dynamically at functions.php of
   the theme using ninja_forms_field ([http://docs.ninjaforms.com/article/146-ninjaformsfield](http://docs.ninjaforms.com/article/146-ninjaformsfield)).
   But what should be the key of that part of the array controlling the dropdown
   options? I try print_r($data) and seems cannot get the key like [label], etc
 *     ```
       [label] => Package
       [input_limit_msg] => character(s) left
       [label_pos] => above
       [list_type] => dropdown
       [multi_size] => 5
       [list_show_value] => 0
   
       => Array
       (
       [options] => Array
       (
       [0] => Array
       (
       [label] => Option 1
       [value] =>
       [calc] =>
       [selected] => 0
       )
       )
       )
   
       [user_info_field_group] =>
       ......
       ```
   
 * [https://wordpress.org/plugins/ninja-forms/](https://wordpress.org/plugins/ninja-forms/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [respectyoda](https://wordpress.org/support/users/respectyoda/)
 * (@respectyoda)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972482)
 * Hello! Thanks for using Ninja Forms. You can easily use that hook to use HTML
   to dynamically add options to the dropdown list. Where are you getting the data
   to add to the dropdown list?
 *  Thread Starter [johnchanmk](https://wordpress.org/support/users/johnchanmk/)
 * (@johnchanmk)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972490)
 * Thanks. I just extract the data from postmeta from wordpress and it could be 
   done successfully. So what should be the way to insert? is it like
 *     ```
       $data['options'] = array(
               array('label'=>'Option 2'),
               array('label'=>'Option 3')
       );
       ```
   
 * ?
 *  [respectyoda](https://wordpress.org/support/users/respectyoda/)
 * (@respectyoda)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972508)
 * Please have a look at this thread: [https://wordpress.org/support/topic/dynamic-lists?replies=18](https://wordpress.org/support/topic/dynamic-lists?replies=18)
 *  [respectyoda](https://wordpress.org/support/users/respectyoda/)
 * (@respectyoda)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972520)
 * Well, I have some sample code for you to inspect and modify based on what you
   need to accomplish:
 *     ```
       function my_filter_function( $data, $field_id ){
       // $data will contain all of the field settings that have been saved for this field.
       // Let's change the default value of the field if it has an ID of 148
          if ( $field_id == 148 ) {
               if ($data['label'] == 'List') {
                   $data['list']['options'] = array(
                       array('label' => 'Nissan', 'value' => null, 'calc' => null, 'selected' => 0),
                       array('label' => 'Kia', 'value' => null, 'calc' => null, 'selected' => 0)
                       );
               }
           }
           return $data;
       }
       add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );
       ```
   
 *  Thread Starter [johnchanmk](https://wordpress.org/support/users/johnchanmk/)
 * (@johnchanmk)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972736)
 * Thanks! the code works well
 *  Thread Starter [johnchanmk](https://wordpress.org/support/users/johnchanmk/)
 * (@johnchanmk)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972737)
 * Furthermore about the question. I tried to create a dynamic list, and how to 
   save the selected option back and display in the backend? It seems that the plugin
   does not save the value.
 * Furthermore, I would like to save the value of a field that the value is changed
   by jquery, is it possible? Thank you for the support.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Set List options dynamically?’ is closed to new replies.

 * ![](https://ps.w.org/ninja-forms/assets/icon-256x256.png?rev=1649747)
 * [Ninja Forms - The Contact Form Builder That Grows With You](https://wordpress.org/plugins/ninja-forms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ninja-forms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ninja-forms/)
 * [Active Topics](https://wordpress.org/support/plugin/ninja-forms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ninja-forms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ninja-forms/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [johnchanmk](https://wordpress.org/support/users/johnchanmk/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/set-list-options-dynamically/#post-5972737)
 * Status: resolved