Thread Starter
floi13
(@floi13)
Solved the issue by doing the following things. Maybe this helps someone who tries a similar thing.
1) add this code to my functions.php:
function dynamic_select_field_values ( $scanned_tag, $replace ) {
if($scanned_tag['name'] != 'YOUR CF7 FIELDNAME HERE') return $scanned_tag;
$rows = get_posts(
array (
'post_type' => 'YOUR CPT NAME HERE',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC'
)
);
if(!$rows) return $scanned_tag;
foreach($rows as $row) {
$scanned_tag['raw_values'][] = $row->post_title . '|' . $row->post_title;
}
$pipes = new WPCF7_Pipes($scanned_tag['raw_values']);
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['pipes'] = $pipes;
return $scanned_tag;
}
add_filter( 'wpcf7_form_tag', 'dynamic_select_field_values', 10, 2);
2) add an element with corresponding name in your CF7 form:
[radio YOUR CF7 FIELDNAME HERE use_label_element default:1]
Hello @floi13,
The solution you applied is brilliant: thanks for sharing your code!
It’s worth mentioning that it also works with select and checkbox fields. I tested it with some sample posts:

Best regards,
Yordan.
Thread Starter
floi13
(@floi13)
Hi Yordan,
Ah, I forgot to mention that, thanks for doing so #thumbsup
Hello from France,
what is:
type’ => ‘YOUR CPT NAME HERE’,
Thanks
Jacques
Thread Starter
floi13
(@floi13)
Hi @jackbluehouse2019
You should replace YOUR CPT NAME HERE with the name of your custom post type.
Hi flo13,
your code works fine with posts. Now I need to do the same thing but with an array of items stored on db.
Do you think it’s possible?
Thanks
Thread Starter
floi13
(@floi13)
I’m not completely sure to be honest… give it a try, I would say.
Worth mentioning is that in my case, it was purely based on a Contact Form 7 form, so didn’t do much if anything with database stuff.
Ok I solved my problem by creating custom posts instead of db items.
Therefor I can use your code to display dynamic content in dropdown menu.
Thanks