I am trying to populate a dropdown field with an array of my custom post type "color".
with this: https://www.gravityhelp.com/documentation/article/dynamically-populating-drop-down-fields/
add_filter( 'gform_pre_render_51', 'color_posts' );
add_filter( 'gform_pre_validation_51', 'color_posts' );
add_filter( 'gform_pre_submission_filter_51', 'color_posts' );
add_filter( 'gform_admin_pre_render_51', 'color_posts' );
function color_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'color_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](http://codex.wordpress.org/Template_Tags/get_posts)
$args = array( 'post_type' => 'color' );
$posts = get_posts( $args );
$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;
}
but even after I set a custom css style to "color_posts" then nothing happens. Anything I am doing wrong or could I do this differently.