Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // replace 1 below with your form id and populate_services with your parameter for dynamic population
- add_filter( 'gform_pre_render_1', 'populate_services' );
- function populate_services( $form ) {
- foreach ( $form['fields'] as &$field ) {
- if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-services' ) === false ) {
- continue;
- }
- $choices = array();
- $terms = get_terms( 'TAXONOMY_HERE', array('hide_empty' => 0));
- foreach( $terms as $term ) {
- $choices[] = array( 'text' => $term->name, 'value' => $term->name );
- }
- $field->placeholder = 'Select a service';
- $field->choices = $choices;
- }
- return $form;
- }
Add Comment
Please, Sign In to add comment