Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function eduprime_get_nested_events()
- {
- // get the meta
- $event_posts = get_posts(array('post_type' => 'tp_event', 'posts_per_page' => -1));
- if( ! $event_posts ) return '';
- $status_meta = array();
- foreach ($event_posts as $single ) {
- $meta = get_post_meta( $single->ID, 'tp_event_status', true );
- if (!in_array($meta, $status_meta)) {
- $status_meta[] = $meta;
- }
- }
- // no terms? bail.
- if( !isset($status_meta) || empty($status_meta) ) return '';
- $out = '';
- //loop through the terms
- foreach( $status_meta as $meta )
- {
- // get videos in each meta
- $events = get_posts(array(
- 'post_type' => 'tp_event',
- 'meta_query' => array(
- array(
- 'key' => 'tp_event_status',
- 'value' => $meta,
- 'compare' => 'IN',
- ),
- ),
- ));
- // no videos? continue!
- if( ! $events ) continue;
- $out .= '<h2>' . esc_html( $meta ) . '</h2>';
- $out .= '<ul>';
- // loop through the video posts
- foreach( $events as $v )
- {
- $link = sprintf(
- '<a href="%s">%s</a>',
- esc_url( get_permalink( $v ) ),
- esc_html( $v->post_title )
- );
- $out .= '<li>' . $link . '</li>';
- }
- $out .= '</ul>';
- }
- return $out;
- }
Add Comment
Please, Sign In to add comment