Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add_filter('gform_pre_render_2', 'rb_populate_posts');
function rb_populate_posts( $form ) {
foreach( $form['fields'] as &$field ){
if( strpos( $field['cssClass'], 'eventsselection' ) === false )
continue;
$posts = get_posts( 'post_type=events&numberposts=-1' );
$choices = array(
array(
'text' => "- Select the event you're registering for -",
'value' => 0
)
);
foreach( $posts as $post ) {
$choices[] = array(
'text' => $post->post_title,
'value' => $post->post_title,
);
}
$field['choices'] = $choices;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment