Populate select/drop down with all events
-
Hi Stephen and all,
I’d like to create dropdown populated with all available tickets.Anybody have a clue how I do this?
I can populate the dropdown in Contact Form 7 with all available event names ( see code below ), but I’d rather have the availabe tickets listed.
In the code I have tried changing ‘post_type’ => ‘event’ to ‘post_type’ => ‘ticket’. That didn’t work.
function cf7_dynamic_select_do_example1($choices, $args=array()) { // this function returns and array of label => value pairs to be used in the select field $choices = array( ' ', 'Choice 1' => 'Choice 1', 'Choice 2' => 'Choice 2', 'Choice 3' => 'Choice 3' ); return $choices; } // end function cf7_dynamic_select_do_example1 add_filter('wpcf7_dynamic_select_example1', 'cf7_dynamic_select_do_example1', 10, 2); function my_event_list() { $posts = get_posts( array( 'post_type' => 'event', 'posts_per_page' => -1, 'order'=> 'ASC', 'orderby' => 'title' ) ); foreach ( $posts as $post ) { $label = $post->post_title; // label of menu select option $value = $post->post_title; // value of menu select option $options[$label] = $value; } return $options; }
- The topic ‘Populate select/drop down with all events’ is closed to new replies.