• Resolved Barcelo

    (@barcelo)


    Hi ??

    I’m currently trying to include a function within functions.php to include upcoming events (f.e. the next 5 events only the dates) in a “Contact Form 7” select field.

    How can I include this as an array?

    Any help would be great – thank you.

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Barcelo

    (@barcelo)

    So, what I have till now:

    function cf7_dynamic_select_field_values ( $hu, $replace ) {  
      
        if ( $hu['name'] != 'tuev-termine' )  
            return $hu;
    
    	global $EventPost;
        $rows = $EventPost->get_events(
        	array (
    //	     'post_type' => 'tuev-termine',
    //	     'numberposts' => '',
    		 'nb' => '10',
    		 'past' => '0',
    	     'order' => 'ASC'
            )
        );  
      
        if ( ! $rows )
            return $hu;
    
        foreach ( $rows as $row ) {
    
            $hu['raw_values'][] = $row->event_begin . ' | ' . $row->event_end;
        }
    
        $pipes = new WPCF7_Pipes($hu['raw_values']);
    
        $hu['values'] = $pipes->collect_befores();
        $hu['labels'] = $pipes->collect_afters();
        $hu['pipes'] = $pipes;
    
        return $hu;
    }
    
    add_filter( 'wpcf7_form_tag', 'cf7_dynamic_select_field_values', 10, 2);

    This works fine except one thing:

    • Time format output is XXXX-XX-XX XX:XX:XX which I would like to have XX.XX.XXXX (only full day events!)

    I tried to format the output, but without success till now.

    Any help would be great – thank you.
    Regards

    Thread Starter Barcelo

    (@barcelo)

    Done

    function cf7_dynamic_select_field_values ( $hu, $replace ) {  
      
        if ( $hu['name'] != 'tuev-termine' )  
            return $hu;
    
    	global $EventPost;
    	$rows = $EventPost->get_events(
        	array (
    		 'nb' => '10',
    		 'past' => '0',
    	     'order' => 'ASC'
            )
        );  
      
        if ( ! $rows )
            return $hu;
    
        foreach ( $rows as $row ) {
    
            $hu['raw_values'][] = date('d.m.Y',strtotime($row->event_begin)) . ' | ' . date('d.m.Y',strtotime($row->event_end));
        }
    
        $pipes = new WPCF7_Pipes($hu['raw_values']);
    	
        $hu['values'] = $pipes->collect_befores();
        $hu['labels'] = $pipes->collect_afters();
        $hu['pipes'] = $pipes;
    
        return $hu;
    }
    
    add_filter( 'wpcf7_form_tag', 'cf7_dynamic_select_field_values', 10, 2);

    Plugin Author Bastien Ho

    (@bastho)

    Glad you’ve found!

    thank you for using Eventpost

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Upcoming events in Contact Form 7 select filed’ is closed to new replies.