ACF Repeater in Dynamic Dropdown
-
I’m getting a bit lost with this and my code is probably completely wrong but I have the following
Add this to Contact Form 7:
[dynamic_select dynamic_select-815 "source:filter"]
And then this in my functions.php file, where:
artist_video – ACF Repeater field name
artist_video_title – ACF Sub field name (text type)
artist_video_id – ACF Sub field name (text type)All that is happening on output is:
<select id="" name="dynamic_select-815" class="wpcf7-form-control cf7sg-dynamic-dropdown wpcf7-dynamic_select"> <option value="choices">Array</option> </select>
add_filter( 'cf7sg_dynamic_dropdown_custom_options','dynamic_select_815_dynamic_options',10,3); function dynamic_select_815_dynamic_options($options, $name, $cf7_key){ $data['choices'] = array(); if( have_rows('artist_video') ) { // while has rows while( have_rows('artist_video') ) { // instantiate row the_row(); // vars $value = get_sub_field('artist_video_title'); $label = get_sub_field('artist_video_id'); // append to choices $options['choices'][ $value ] = $label; } } foreach($data as $label=>$value){ $options['choices'][ $value ] = $label; } return $options; }
Any ideas or help would be much appreciated.
- The topic ‘ACF Repeater in Dynamic Dropdown’ is closed to new replies.