Hi there, I was looking for a simple solution to pass a set of ACF custom fields values of a sub_field (coming from a repeater field) and pass them to a custom select of CF7 (dynamically populated). I tried looking elsewhere on stackexchange, here on documentation and google, but I can’t find an exhaustive solution, realistically for my limited programming knowledge.
I hope in your answer and in a future release of Custom Dynamic Fields for ACF π
I found a solution! I hope it will be useful for someone else in future:
function add_date_to_cf7() {
$output = "<select name='date_corso' id='date_corso' onchange='document.getElementById(\"date_corso\").value=this.value;'><option></option>";
if( have_rows('gruppo_date') ) {
while( have_rows('gruppo_date') ) {
the_row();
$output .= '<option value="'.get_sub_field('intervallo_date_corso').'">' .get_sub_field('intervallo_date_corso'). '</option>';
}
}
$output .= "</select>";
return $output;
}
wpcf7_add_shortcode('date_corso', 'add_date_to_cf7', true);