Last active
August 29, 2015 14:05
-
-
Save halfempty/423b15fc61e8d5157569 to your computer and use it in GitHub Desktop.
Gravity Forms populate
This file contains hidden or 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
<?php | |
function populate_checkbox($form) { | |
if ( $form['id'] != 15 ) : | |
return $form; | |
endif; | |
foreach($form['fields'] as &$field) : | |
$field_id = 16; // The ID of the field to be populated | |
if( $field['id'] != $field_id ) : | |
continue; | |
endif; | |
$posts = tribe_get_events( | |
array( | |
'eventDisplay'=>'upcoming', | |
'posts_per_page'=>-1, | |
'tax_query'=> array( | |
array( | |
'taxonomy' => 'tribe_events_cat', | |
'field'=>'slug', | |
'terms' =>'teachers' | |
) | |
) | |
) | |
); | |
$input_id = 1; | |
foreach($posts as $post) : | |
$mcaevents = get_post_meta($post->ID,'_mcaevents',TRUE); | |
if ( $mcaevents['soldout'] != true && !event_geneology_by_id('field-trip-program',$post->ID) && $post->post_name != 'teacher-institute' && $post->post_name != 'teacher-workshop-bowie' ) : | |
if ( $input_id % 10 == 0 ) : | |
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs) | |
$input_id++; | |
endif; | |
$text = '<strong>' . $post->post_title . '</strong> (' . marty_return_sp_date( $post->ID ) . ')'; | |
$choices[] = array('text' => $text, 'value' => $post->post_title); | |
$inputs[] = array("label" => $post->post_title, "id" => "{$field_id}.{$input_id}"); | |
$input_id++; | |
endif; | |
endforeach; | |
$field['choices'] = $choices; | |
$field['inputs'] = $inputs; | |
endforeach; | |
return $form; | |
} | |
add_filter( 'gform_pre_render', 'populate_checkbox' ); | |
add_filter( 'gform_pre_validation', 'populate_checkbox' ); | |
add_filter( 'gform_pre_submission_filter', 'populate_checkbox' ); | |
add_filter( 'gform_admin_pre_render', 'populate_checkbox' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment