pull out data from database and display in Gravity form

admin

Administrator
Staff member
I am using gravity forms plugin, and I'm trying to display the categories as a drop down list in the form I have already created.

<a href=" " rel="nofollow noreferrer"><img src=" " alt="enter image description here"></a>

If required, please here's a link to <a href="http://www.martcircle.com" rel="nofollow noreferrer">my website</a>

I've been on this for too long, and no way out. Kindly help me out.

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override">
Code:
add_filter( 'gform_pre_render_1', 'populate_categories' );
add_filter( 'gform_pre_validation_1', 'populate_categories' );
add_filter( 'gform_pre_submission_filter_1', 'populate_categories' );
add_filter( 'gform_admin_pre_render_1', 'populate_categories' );
function populate_categories( $form ) {

    foreach ( $form['fields'] as &amp;$field ) {

        if ( $field-&gt;id != 1 ) {
            continue;
        }

        // you can add additional parameters here to alter the posts that are retrieved
        // more info: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
        $categories = get_categories ;

        $choices = array();

        foreach ( $categories as $categories ) {
            $choices[] = array( 'text' =&gt; $categories-&gt;name, 'value' =&gt; $categories-&gt;name );
        }

        // update 'Select a Post' to whatever you'd like the instructive option to be
        $field-&gt;placeholder = 'Category';
        $field-&gt;choices = $choices;

    }

    return $form;
}
</div>
</div>