Integrating with Gravity Forms
-
I am building a Gravity form and want a form selector to be populated with events of a specific category – in the future.
The code below will return 5 events in the gravity form drop down but I need to try and filter them somehow.
$posts = get_posts( ‘numberposts=5&post_type=event’ );
I have tried all different things here but to no avail!
add_filter('gform_pre_render_1', 'get_events'); add_filter('gform_pre_validation_1', 'get_events'); add_filter('gform_pre_submission_filter_1', 'get_events'); add_filter('gform_admin_pre_render_1', 'get_events'); function get_events( $form ) { foreach ( $form['fields'] as &$field ) { if ( $field['type'] == 'select' ) { $posts = get_posts( 'numberposts=5&post_type=event' ); $choices = array(); foreach ( $posts as $post ) { $choices[] = array( 'text' => $post->post_title, 'value' => $post->id); } $field['placeholder'] = 'Select an event'; $field['choices'] = $choices; } } return $form; }
- The topic ‘Integrating with Gravity Forms’ is closed to new replies.