Created
April 17, 2018 08:37
-
-
Save mlbd/da2cbf117a55924fb2a551400412834e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment