function dynamic_select_field_values ( $scanned_tag, $replace )
{
if ( $scanned_tag[‘name’] != ‘products’ )
return $scanned_tag;
$rows = get_posts(
array (
‘post_type’ => ‘products’,
‘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[‘labels’] = $pipes->collect_afters();
$scanned_tag[‘pipes’] = $pipes;
return $scanned_tag;
}
add_filter( ‘wpcf7_form_tag’, ‘dynamic_select_field_values’, 10, 2);