//Contact form 7 dynamic value
//shortcode [checkbox checkbox-957 values:builder-list] select & radio also work
function cf7DynamicListBuilder($tag)
{
$options = $tag['options'];
if (!isset($options))
return $tag;
foreach ($options as $option)
if (preg_match('%^values:([-0-9a-zA-Z_]+)$%', $option, $matches))
$arg = $matches[1];
if (!isset($arg))
return $tag;
switch ($arg) {
case 'builder-list':
continue;
break;
default:
return $tag;
break;
}
$args = [
'post_type' => 'home-builder',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC'
];
$posts = get_posts($args);
if (!$posts)
return $tag;
foreach ($posts as $post) {
$tag['raw_values'][] = $post->post_title;
$tag['values'][] = $post->post_title;
$tag['labels'][] = $post->post_title;
}
return $tag;
}
add_filter('wpcf7_form_tag', 'cf7DynamicListBuilder', 10, 2);
Jagdish Sarma Asked question May 5, 2022