I've snagged some code from this forum that helps me dynamically populate a category of posts into a drop down menu.
However, If i try to use a custom field drop down menu instead of a regular drop down menu (using same specifications), the drop down will not dynamically populate.
/* Dynamic drop-down on /register
------------------------------------------------------ */
add_filter('gform_pre_render_1', '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('numberposts=-1&post_status=publish&category_name=members');
$choices = array(array('text' => 'Select a member company', 'value' => ' '));
foreach($posts as $post){
$choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
}
$field['choices'] = $choices;
}
return $form;
}
Any ideas on what I can do differently with this script to ensure I can dynamically populate a custom field (drop down) ?