从数据库中提取数据并以Gravity形式显示

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.

enter image description here

If required, please here's a link to my website

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

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 &$field ) {

        if ( $field->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' => $categories->name, 'value' => $categories->name );
        }

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

    }

    return $form;
}

</div>

You can dynamically generate drop downs for gravity forms using the syntax provided below in this link. You have to take control over the functions.php file of the theme to retrieve your output as per your requirement.

Here is the clear documentation provided and you can create in a simple manner using this methods. There are two methods available refer to it.

https://www.gravityhelp.com/documentation/article/dynamically-populating-drop-down-fields/

If you face any problem with creation let me know we shall solve it.