can you post your code? I think you just need to fill the value field (in addition to $tag->name)
Thread Starter
qbaas
(@qbaas)
Thanks for asking!
In the contact form, I have:
[select* your-coach class:cf7-field data:vccoach placeholder “Coach”]</label>
In functions.php, this is the corresponding part:
add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
if (in_array('vccoach', $options)){
$coaches = getCoaches();
return $coaches;
}
return $n;
}, 10, 3);
getCoaches() is a method that gets data from an external API endpoint.
In that method I construct a new array from the JSON output by the external API endpoint, consisting of ID’s and Names. In a foreach loop through the response, this code:
array_push($coaches, $coach['Id'] . '|' . $coach['Name']);
… builds an array that consists of entries like :
[“024|John Doe”,”026|Joan Does”, …]
But the result of this, is 024|John Doe and 062|Joan Does … as options in the contact form select field, so the Pipe character isn’t interpreted like it is in strings literals.
What am I missing? Thanks again for any help!
isn’t easy without seeing the final array defined by getCoaches() but however check how listo does this in contact-form-7/modules/listo.php because it is exactly what you are looking for:
foreach ( (array) $options as $option ) {
$option = explode( '.', $option );
$type = $option[0];
$args['group'] = isset( $option[1] ) ? $option[1] : null;
if ( $list = listo( $type, $args ) ) {
$data = array_merge( (array) $data, $list );
}
}