Advertisement
Guest User

WP Questions - 7930 -2

a guest
Jan 25th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. $tournaments = get_field( 'tournament_selection' );
  4.  
  5. var_dump( $tournaments );
  6.  
  7. function format_tournament( $id ) {
  8.     $date = DateTime::createFromFormat( 'Ymd', get_field('tournament_date', $id) );
  9.     return sprintf( '<li><a href="%s">%s</a><span>%s</span></li>', get_permalink($id), get_field('tournament_name', $id), $date->format('F d, Y') );
  10. }
  11.  
  12.  
  13. if( $tournaments ) {
  14.  
  15.     $upcoming = '';
  16.     $finished = '';
  17.  
  18.  
  19. foreach( $tournaments as $tournament ) {
  20.  
  21.     $terms = wp_get_object_terms( $tournament, 'category', array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'slug') );
  22.    
  23.     if( in_array( 'upcoming-tournament', $terms ) ) {
  24.         $upcoming .= format_tournament( $tournament );
  25.     }
  26.    
  27.     if( in_array( 'finished-tournament', $terms ) ) {
  28.         $finished .= format_tournament( $tournament );
  29.     }
  30. }        
  31.  
  32. ?>
  33.  
  34.  
  35. <h3>Upcoming Tournaments</h3>
  36. <ul><?php echo $upcoming; ?></ul>
  37.  
  38. <h3>Finished Tournaments</h3>
  39. <ul><?php echo $finished; ?></ul>
  40.  
  41.  
  42. <?php
  43.  
  44. }
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement