In functions.php (_2 is ID)
add_filter( 'gform_pre_render_2', 'populate_posts_product' );
add_filter( 'gform_pre_validation_2', 'populate_posts_product' );
add_filter( 'gform_pre_submission_filter_2', 'populate_posts_product' );
add_filter( 'gform_admin_pre_render_2', 'populate_posts_product' );
function populate_posts_product( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'vakgebieden' ) === false ) {
continue;
}
$terms = get_terms( array(
'taxonomy' => 'vacatures_cat',
'hide_empty' => false,
) );
//$posts = get_posts( 'numberposts=-1&post_status=publish&post_type=specialisten' );
$choices = array();
foreach ( $terms as $term ) {
$choices[] = array(
'text' => $term->name,
'value' => $term->slug
);
}
/*foreach ( $posts as $post ) {
$choices[] = array(
'text' => $post->post_title,
'value' => $post->post_title
);
}*/
$field->choices = $choices;
}
return $form;
}
#custom #functions #Gravity Forms #taxonomy