• oltrenubi

    (@oltrenubi)


    Hello everyone,

    I’m encountering an issue with a select field dynamically populated using a custom function. The select field is populated correctly, but in the email sent, the values assigned to the [select_dynamic] and [_raw_select_dynamic] tags are identical.

    After conducting various tests, I noticed that if I manually insert the post ID in the line of code “$date_corso = get_field('date_del_corso', get_the_ID());" making it, for example, “$date_corso = get_field('date_del_corso', 9863);“, everything works perfectly, and the values in the email are correctly submitted.

    Of course, I’ve already verified that the value returned by get_the_ID() is correct.

    Here’s the entire code:

    function dynamic_select_field_values ( $scanned_tag, $replace ) {  
    
        if ( $scanned_tag['name'] != 'select_dynamic' )  
            return $scanned_tag;
    
        $date_corso = get_field('date_del_corso', get_the_ID());
    
        if (isset($date_corso)) {
            foreach ($date_corso as $d) {
                $today = strtotime(date('Ymd'));
                $data = get_field('data_corso', $d);
                $location = get_field('location_corso', $d);
                $timestamp = strtotime($data);
                setlocale(LC_TIME, 'it_IT.utf8');
                $giorno_testuale = ucfirst(strftime('%A', $timestamp));
                $giorno_numerico = date('d', $timestamp);
                $mese_testuale = ucfirst(strftime('%B', $timestamp));
                $anno_numerico = date('Y', $timestamp);
                $option = $giorno_numerico . " " . $mese_testuale . " " . $anno_numerico . " - " . $location;
                
                if($today < strtotime($data)) {
                    $scanned_tag['raw_values'][] =  $d . '|' .  $option;
                }
            }
        }
    
        $pipes = new WPCF7_Pipes($scanned_tag['raw_values']);
        $scanned_tag['labels'] = $pipes->collect_afters(); // this is the html info for each option
        $scanned_tag['pipes'] = $pipes; // this is separator
        $scanned_tag['values'] = $pipes->collect_befores(); // this is the value for each option
    
        return $scanned_tag;  
    }  
    
    add_filter( 'wpcf7_form_tag', 'dynamic_select_field_values', 10, 2); 

    Thank you in advance for your help and suggestions!

  • The topic ‘Issue with dynamic select fields email output’ is closed to new replies.