Guest User

Untitled

a guest
Apr 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. function eduprime_get_nested_events()
  2. {
  3. // get the meta
  4. $event_posts = get_posts(array('post_type' => 'tp_event', 'posts_per_page' => -1));
  5. if( ! $event_posts ) return '';
  6.  
  7. $status_meta = array();
  8. foreach ($event_posts as $single ) {
  9. $meta = get_post_meta( $single->ID, 'tp_event_status', true );
  10. if (!in_array($meta, $status_meta)) {
  11. $status_meta[] = $meta;
  12. }
  13. }
  14.  
  15. // no terms? bail.
  16. if( !isset($status_meta) || empty($status_meta) ) return '';
  17.  
  18. $out = '';
  19.  
  20. //loop through the terms
  21. foreach( $status_meta as $meta )
  22. {
  23. // get videos in each meta
  24. $events = get_posts(array(
  25. 'post_type' => 'tp_event',
  26. 'meta_query' => array(
  27. array(
  28. 'key' => 'tp_event_status',
  29. 'value' => $meta,
  30. 'compare' => 'IN',
  31. ),
  32. ),
  33. ));
  34.  
  35. // no videos? continue!
  36. if( ! $events ) continue;
  37. $out .= '<h2>' . esc_html( $meta ) . '</h2>';
  38. $out .= '<ul>';
  39. // loop through the video posts
  40. foreach( $events as $v )
  41. {
  42. $link = sprintf(
  43. '<a href="%s">%s</a>',
  44. esc_url( get_permalink( $v ) ),
  45. esc_html( $v->post_title )
  46. );
  47. $out .= '<li>' . $link . '</li>';
  48. }
  49. $out .= '</ul>';
  50. }
  51. return $out;
  52. }
Add Comment
Please, Sign In to add comment