Hi guys,
I am using Gravity forms for a couple of months now. And I love it. I need to create a form where I have 2 dropdowns the name of the current “day” which is an ACF select field value linked to each custom post type “workshop”. So each workshops has it’s own DAY selection.
The second dropdown is where I have “workshops” and each workshop is given on the specific selected current date.
So, if you select Monday only Workshop A and B should be filtered and shown in the dropdowns.
I have managed to display the custom post type “posts” inside the dropdown. But I want to re-fresh these values based on the selection and if meta query key/values matches or is linked to this workshop ( the current date name ).
This is my code:
<?php
add_filter( 'gform_pre_render_1', 'populate_workshops' );
add_filter( 'gform_pre_validation_1', 'populate_workshops' );
add_filter( 'gform_pre_submission_filter_1', 'populate_workshops' );
add_filter( 'gform_admin_pre_render_1', 'populate_workshops' );
function populate_workshops( $form ) {
$field = get_field_object('workshop_date_day');
var_dump($field);
foreach ( $form['fields'] as $field ) {
if ( $field->type != 'dropdown ' && $field->id === 9 ) {
//
}
if ( $field->type != 'dropdown ' && $field->id === 12 ) {
$workshops = array(
'post_type' => 'workshops',
'post_status' => 'publish',
'posts_per_page' => -1
);
$posts = get_posts( $workshops );
$choices = array();
foreach ( $posts as $post ) {
$choices[] = array(
'order' => 'ASC',
'orderby' => 'title',
'text' => $post->post_title,
'value' => get_permalink($post->ID)
);
}
$field->placeholder = 'Kies een optie';
$field->choices = $choices;
}
}
return $form;
}
Thanks in advance