Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mandiwise/8ffe54411b31ff1e7fff to your computer and use it in GitHub Desktop.
Save mandiwise/8ffe54411b31ff1e7fff to your computer and use it in GitHub Desktop.
Using gform_pre_render_[form ID] for Auto-population
function populate_concept_nominees( $form ){
foreach ( $form['fields'] as &$field ){
// Set a custom CSS class for your field and grab onto it here
if ( $field['type'] != 'select' || strpos( $field['cssClass'], 'populate-concept' ) === false )
continue;
// Query parameters for get_posts
$args = array(
'numberposts' => -1,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'nominee',
'tax_query' => array(
array(
'taxonomy' => 'award-category',
'field' => 'slug',
'terms' => 'concept'
)
)
);
$posts = get_posts( $args );
// The default option at the top of the list
$choices = array( array( 'text' => '-- Select a Nominee --', 'value' => ' ' ) );
// Now grab all of the posts that match the above query and add them to the dropdown one by one
foreach ( $posts as $post ){
$choices[] = array( 'text' => wptexturize( $post->post_title ), 'value' => wptexturize( $post->post_title ) );
}
$field['choices'] = $choices;
}
return $form;
}
add_filter( 'gform_pre_render_[form ID]', 'populate_concept_nominees' );
@AhmadRaza9
Copy link

@mandiwise
hi, hope you are well.

I have an issue, If I create gravity form dynamic field and then I submit the form i have no data in email
Can you tell me what issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment