Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'gform_pre_render_2', 'populate_posts' );
- add_filter( 'gform_pre_validation_2', 'populate_posts' );
- add_filter( 'gform_pre_submission_filter_2', 'populate_posts' );
- add_filter( 'gform_admin_pre_render_2', 'populate_posts' );
- function populate_posts( $form ){
- foreach ( $form['fields'] as &$field ) {
- if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
- continue;
- }
- $posts = get_posts(array(
- 'numberposts' => -1,
- 'post_type' => 'staff',
- ));
- $choices = array();
- foreach ( $posts as $post ) {
- $choices[] = array(
- 'text' => $post->post_title,
- '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
- );
- }
- $field->placeholder = 'Select Staff Member';
- $field->choices = $choices;
- }
- return $form;
- }
Add Comment
Please, Sign In to add comment