Default Dynamic Dropdown value: how to set??
-
Given the code below, how do I set the default selected value?? Having trouble finding a clear answer anywhere
add_filter( 'wpcf7_form_tag', 'customDropdownFunction', 10, 2); //add a new form tag function function customDropdownFunction($options){ if ( $options['name'] != 'customDropdown' ) { //check if the name of your tag is the same as step 2 — if its the same, run the function, if not then ignore return $options; } global $wpdb; //use WordPress database connection or replace with your own for external / not in WP database table //$data = $wpdb->get_results( "SELECT * FROM database_table" ); //select frmom custom database table inside of WP database or replace with whatever you need $data = array( '1' => 'one', '2' => 'two', '3' => 'three' ); foreach($data as $value=>$label){ $options['raw_values'][] = $value . '|' . $label; //using pipes to put the value before the pipe and the label after by picking up the ID and LabelName fields from the database } $pipes = new WPCF7_Pipes($options['raw_values']); //use the WPCF7_Pipes class $options['values'] = $pipes->collect_befores(); //get value vefore pipe $options['pipes'] = $pipes; $options['labels'] = $pipes->collect_afters(); //get label after pipe return $options; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Default Dynamic Dropdown value: how to set??’ is closed to new replies.