dima7b
4/25/2014 - 2:19 PM

populate_posts.php

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;
        
        // you can add additional parameters here to alter the posts that are retreieved
        // more info: http://codex.wordpress.org/Template_Tags/get_posts
        $posts = get_posts('post_type=client&numberposts=-1');
        
        // update 'Select a Post' to whatever you'd like the instructive option to be
        $choices = array(array('text' => 'Select a Talent', 'value' => ' '));
        
        foreach($posts as $post){
            $choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
        }
        
        $field['choices'] = $choices;
        
    }
    
    return $form;
}