I finally use:
function dynamic_select_list($tag, $unused) {
$options = (array)$tag['options'];
foreach ($options as $option) {
if (preg_match('%^from_db:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
$from_db = $matches[1];
}
}
if(!isset($from_db)) {
return $tag;
}
// get the existing WPCF7_Pipe objects
$befores = $tag['pipes']->collect_befores();
$afters = $tag['pipes']->collect_afters();
// add the existing WPCF7_Pipe objects to the new pipes array
$pipes_new = array();
for ($i=0; $i < count($befores); $i++) {
$pipes_new[] = $befores[$i] . '|' . $afters[$i];
}
// Add stores to the $tag values
if($from_db === 'stores') {
global $post;
$args = array( 'post_type' => 'wpsl_stores','posts_per_page' => -1, 'meta_key' => 'wpsl_zip','orderby' => array(
'meta_value_num' => 'ASC',
'post_date' => 'ASC',
), );
$myposts = get_posts( $args );
if (!$myposts) {
return $tag;
}
foreach ($myposts as $post) {
$title = get_the_title();
$zip = get_post_meta($post->ID, 'wpsl_zip', true);
$city = get_post_meta($post->ID, 'wpsl_city', true);
$email = get_post_meta($post->ID, 'wpsl_email', true);
$tag['raw_values'][] = $email;
$tag['values'][] = $title;
$tag['labels'][] = $zip . ' '. $city .' - ' . $title;
// add the store info for use as a new WPCF7_Pipe object
$pipes_new[] = $title . '|' . $email;
}
wp_reset_postdata();
}
// setup all the WPCF7_Pipe objects
$tag['pipes'] = new WPCF7_Pipes($pipes_new);
return $tag;
}
add_filter('wpcf7_form_tag', 'dynamic_select_list', 10, 2);
Then I add shortcode in contact form tab:
[select* store default:get id:store class:store from_db:stores]
And [store] in the “To” field of Email tab.
Also “Magasin : [_raw_store] in the content Email tab to get the name of the store
Thanks to default:get parameter it is possible to get an URL link of items in the dropdown.
Now I’m looking for a way to get this:
The Post store ID as option value but still get store label in the email content.
<select>
<option value=”1″>Store 1</option>
<option value=”2″>Store 2</option>
</select>