Last active
March 22, 2023 12:40
-
-
Save mandiwise/8ffe54411b31ff1e7fff to your computer and use it in GitHub Desktop.
Using gform_pre_render_[form ID] for Auto-population
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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?