• I use the following code to fill a select with posts from a custom post type:

    function form_posttype_field ( $tag, $unused ) {
    
    if ( $tag['name'] != 'seminarnumber' )
        return $tag;
    
    $args = array (
        'numberposts'   => -1,
        'post_type'     => 'seminars',
        'orderby'       => 'title',
        'order'         => 'ASC',
    );
    
    $custom_posts = get_posts($args);
    
    if ( ! $custom_posts )
        return $tag;
    
    foreach ( $custom_posts as $custom_post ) {
    	$ID = $custom_post->ID;
    	if(get_field('seminar_number', $ID)){
    		$tag['values'][] = get_field('seminar_number', $ID);
    		$tag['raw_values'][] = $custom_post->post_title;  
    		$tag['labels'][] = $custom_post->post_title;
    	}else{
    		 $tag['values'][] = $custom_post->post_title;
    		 $tag['raw_values'][] = $custom_post->post_title; 
             $tag['labels'][] = $custom_post->post_title;		 
    	}
         
    
    }
    
    return $tag;
    }
    
    add_filter( 'wpcf7_form_tag', 'form_posttype_field', 10, 2);

    Works great, but there is one thing I can’t get to run.
    I fill the value with a short ID of the seminar and the label with the long title.
    In HTML this looks like this:
    <option value="W34-2017">W34-2017 = Syst. Case Management/Fallmanagement 2017 (ab 05.10.2017)</option>
    But I have no idea how to get the long title (= the label) to send it with the email.
    I tried to fill $tag[‘raw_values’][] also with the long title and get this with [_raw_seminarnumber], but I always get the short ID (except if I fill $tag[‘values’][] also with $custom_post->post_title, but that’s not what I want … because I want to preselect an option via url parameter and for this the long title would be to long and to error-prone).

    Any ideas how to get the label for sending it with the email?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Get label from dynamically generated select option’ is closed to new replies.