maximus87

Untitled

Jul 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. // replace 1 below with your form id and populate_services with your parameter for dynamic population
  2.  
  3. add_filter( 'gform_pre_render_1', 'populate_services' );
  4. function populate_services( $form ) {
  5.  
  6.     foreach ( $form['fields'] as &$field ) {
  7.  
  8.         if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-services' ) === false ) {
  9.             continue;
  10.         }
  11.         $choices = array();
  12.         $terms = get_terms( 'TAXONOMY_HERE', array('hide_empty' => 0));
  13.         foreach( $terms as $term ) {
  14.             $choices[] = array( 'text' => $term->name, 'value' => $term->name );
  15.         }
  16.         $field->placeholder = 'Select a service';
  17.         $field->choices = $choices;
  18.  
  19.     }
  20.  
  21.     return $form;
  22. }
Add Comment
Please, Sign In to add comment