Guest User

Untitled

a guest
Jun 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. add_filter( 'gform_pre_render_2', 'populate_posts' );
  2. add_filter( 'gform_pre_validation_2', 'populate_posts' );
  3. add_filter( 'gform_pre_submission_filter_2', 'populate_posts' );
  4. add_filter( 'gform_admin_pre_render_2', 'populate_posts' );
  5.  
  6.  
  7. function populate_posts( $form ){
  8.  
  9. foreach ( $form['fields'] as &$field ) {
  10. if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
  11. continue;
  12. }
  13.  
  14. $posts = get_posts(array(
  15. 'numberposts' => -1,
  16. 'post_type' => 'staff',
  17. ));
  18.  
  19. $choices = array();
  20.  
  21. foreach ( $posts as $post ) {
  22. $choices[] = array(
  23. 'text' => $post->post_title,
  24. 'value' => $post->ID, //** <- I am using post ID , because url parameter need to be the post id. also i need to send post title when submit the form
  25. );
  26. }
  27.  
  28. $field->placeholder = 'Select Staff Member';
  29. $field->choices = $choices;
  30. }
  31.  
  32. return $form;
  33.  
  34. }
Add Comment
Please, Sign In to add comment