Skip to content

Instantly share code, notes, and snippets.

@jonschr
Created August 21, 2014 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschr/85b45c4ecd23703a19f9 to your computer and use it in GitHub Desktop.
Save jonschr/85b45c4ecd23703a19f9 to your computer and use it in GitHub Desktop.
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