Title: Dynamic Dropdown Custom Options
Last modified: September 23, 2020

---

# Dynamic Dropdown Custom Options

 *  Resolved [jasonjonesbuild](https://wordpress.org/support/users/jasonjonesbuild/)
 * (@jasonjonesbuild)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/)
 * Hi. I’ve been trying to implement dynamic dropdown custom options with the filter
   you’ve provided:
    add_filter( ‘cf7sg_dynamic_dropdown_custom_options’,’dynamic_select_000_dynamic_options’,
   10,3);.
 * So far, I haven’t been able to make it work.
 * Can you help me?
 * Here is how I did it:
 * I’ve tried it in two different ways:
 * First method: Setup Data through hard-code
 *     ```
       $data = array(
           "group_label"  => array(
           			"group_optionss" => array(
       				    		"label1" => "value1",
       				    		"label2" => "value2",
       				    		"label3" => "value3",
       				    		)
           			)
         );
       foreach($data as $group_label=>$group_opts){
           $options .= '<optgroup label="'.$group_label.'">';
           foreach($group_opts as $label=>$value){
             $options .= '<option value="'.$value.'">'.$label.'</option>';
           }
           $options .= '</optgroup>';
         }
       return $options;
       ```
   
 * Second method: Use options directly
 *     ```
       $options .= '<optgroup label="group_label">';
       $options .= '<option value="value1">label1</option>';
       $options .= '<option value="value2">label2</option>';
       $options .= '<option value="value3">label3</option>';
       $options .= '</optgroup>';
       return $options;
       ```
   
 * Honestly, I thought it was gonna work on the second method. Can you help me implement
   your filter code for dynamic dropdown custom options?
    -  This topic was modified 5 years, 8 months ago by [jasonjonesbuild](https://wordpress.org/support/users/jasonjonesbuild/).
    -  This topic was modified 5 years, 8 months ago by [jasonjonesbuild](https://wordpress.org/support/users/jasonjonesbuild/).

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

 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/#post-13443893)
 * your code looks fine. The only reason I can think that it’s no working is because
   the filter function isn’t being called.
 * the filter helper code includes 2 checks on the form unique key and the field
   name, for example,
 *     ```
       if('test-accordion'!==$cf7_key || 'my-list' !== $name){
           return $options;
         }
       ```
   
 * hence if either the form key or field name has changed, the function returns 
   an empty set of options.
 * can you check that you function is being properly called (write something to 
   your debug log file for example);
 *  Thread Starter [jasonjonesbuild](https://wordpress.org/support/users/jasonjonesbuild/)
 * (@jasonjonesbuild)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/#post-13444818)
 * Thanks for the quick response.
 * Yes, I have the filter function set up already. However I dont know if it’s being
   called. What do I write on the debug log file and where can I see if its being
   called?
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/#post-13447488)
 * > However I dont know if it’s being called. What do I write on the debug log 
   > file and where can I see if its being called?
 * you’ll need to read up on [debugging in WordPress](https://wordpress.org/support/article/debugging-in-wordpress/),
   and [enabling your debug.log file](https://help.dreamhost.com/hc/en-us/articles/360029327771-Enabling-the-WordPress-Debug-log).
 *  Plugin Author [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * (@aurovrata)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/#post-13659504)
 * I am marking this as resolved since I have not heard back from you

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

The topic ‘Dynamic Dropdown Custom Options’ is closed to new replies.

 * ![](https://ps.w.org/cf7-grid-layout/assets/icon-256x256.png?rev=1834229)
 * [Smart Grid-Layout Design for Contact Form 7](https://wordpress.org/plugins/cf7-grid-layout/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-grid-layout/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-grid-layout/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-grid-layout/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-grid-layout/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-grid-layout/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Aurovrata Venet](https://wordpress.org/support/users/aurovrata/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/dynamic-dropdown-custom-options/#post-13659504)
 * Status: resolved