In functions.php

add_filter( 'gform_pre_render_2', 'populate_posts' ); // Vul in plaats van de 2 het FORM ID in
add_filter( 'gform_pre_validation_2', 'populate_posts' ); 
add_filter( 'gform_pre_submission_filter_2', 'populate_posts' );
add_filter( 'gform_admin_pre_render_2', 'populate_posts' );
function populate_posts( $form ) {
 
    foreach ( $form['fields'] as &$field ) {
 
        if ( $field->type != 'select' || strpos( $field->cssClass, 'specialisten' ) === false ) { // Het moet een select veld zijn met de CSS class "specialisten"
            continue;
        }
 
        // you can add additional parameters here to alter the posts that are retrieved
        // more info: http://codex.wordpress.org/Template_Tags/get_posts
        $posts = get_posts( 'numberposts=-1&post_status=publish&post_type=specialisten' ); // Voer hier de query in
 
        $choices = array();
 
        foreach ( $posts as $post ) {
            $choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );
        }
 
        // update 'Select a Post' to whatever you'd like the instructive option to be
        $field->placeholder = 'Selecteer een specialist';
        $field->choices = $choices;
 
    }
 
    return $form;
}

 

Geef een reactie 0