Accessing $entry field from gravity forms populate posts function. Is it possible?

by jack bauer   Last Updated August 13, 2019 18:08 PM

We're trying to use rgar to read the $entry from a given field, but there is no $entry variable accessible. When we change the function to populate_posts ( $form, $entry ) the page fails to load. How can we access the $entry variable? Thanks

add_filter( 'gform_pre_render_51', 'populate_posts' );
add_filter( 'gform_pre_validation_51', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_51', 'populate_posts' );
add_filter( 'gform_admin_pre_render_51', '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 retrieved
        // more info: http://codex.wordpress.org/Template_Tags/get_posts
        $posts = get_posts( 'numberposts=-1&post_status=publish' );

        $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 = 'Select a Post';
        $field->choices = $choices;

    }

    return $form;
}


Related Questions


Updated February 22, 2018 16:08 PM

Updated November 28, 2017 16:08 PM

Updated September 27, 2017 23:08 PM

Updated March 17, 2017 15:08 PM

Updated February 26, 2016 01:03 AM