Created
          July 21, 2022 19:07 
        
      - 
      
 - 
        
Save mwhiteley16/ad6456ad66752c88ed522ad9399c2ff5 to your computer and use it in GitHub Desktop.  
    Potomac Dashboard Query
  
        
  
    
      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
    
  
  
    
  | <?php | |
| wp_reset_query(); | |
| $event_ids = []; | |
| // get events hosted by current user | |
| $args_host = [ | |
| 'author' => get_current_user_id(), | |
| 'post_type' => 'events', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'meta_query' => [ | |
| [ | |
| 'key' => 'wd_event_ends', | |
| 'value' => date('Y-m-d'), | |
| 'type' => 'DATE', | |
| 'compare' => '>=', | |
| ] | |
| ], | |
| ]; | |
| $event_host_query = new WP_Query( $args_host ); | |
| if ( $event_host_query->have_posts() ) { | |
| while ( $event_host_query->have_posts() ) : $event_host_query->the_post(); | |
| $event_ids[] = get_the_ID(); | |
| endwhile; | |
| wp_reset_query(); | |
| } | |
| // get events user is registered for | |
| global $current_user; | |
| $args_attendees = [ | |
| 'author__not_in' => [ get_current_user_id() ], | |
| 'post_type' => 'events', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'meta_query' => [ | |
| [ | |
| 'key' => 'wd_event_ends', | |
| 'value' => date('Y-m-d'), | |
| 'type' => 'DATE', | |
| 'compare' => '>=', | |
| ] | |
| ], | |
| ]; | |
| $event_attendees_query = new WP_Query( $args_attendees ); | |
| if ( $event_attendees_query->have_posts() ) { | |
| while ( $event_attendees_query->have_posts() ) : $event_attendees_query->the_post(); | |
| if ( have_rows( 'wd_event_attendees' ) ) { | |
| while ( have_rows( 'wd_event_attendees' ) ) : the_row(); | |
| if ( $current_user->user_email == get_sub_field( 'wd_email_address' ) ) { | |
| $event_ids[] = get_the_ID(); | |
| break; | |
| } | |
| endwhile; | |
| } | |
| endwhile; | |
| wp_reset_query(); | |
| } | |
| // output all events including author events and attendees events | |
| $args = [ | |
| 'post_type' => 'events', | |
| 'post_status' => [ 'publish' ], | |
| 'post__in' => $event_ids, | |
| 'posts_per_page' => -1, | |
| 'order' => 'ASC', | |
| 'orderby' => 'meta_value', | |
| 'meta_key' => 'wd_event_ends', | |
| 'facetwp' => true, | |
| 'meta_query' => [ | |
| [ | |
| 'key' => 'wd_event_ends', | |
| 'value' => date('Y-m-d'), | |
| 'type' => 'DATE', | |
| 'compare' => '>=', | |
| ] | |
| ], | |
| ]; | |
| $event_query = new WP_Query( $args ); | |
| if ( $event_query->have_posts() && ! empty( $event_ids ) ) { | |
| echo '<div class="user-dashboard__events facetwp-template">'; | |
| while ( $event_query->have_posts() ) : $event_query->the_post(); | |
| get_template_part( '/partials/loop/loop-item-dashboard' ); | |
| endwhile; | |
| echo '</div>'; | |
| wp_reset_query(); | |
| } else { | |
| echo '<div class="no-events">'; | |
| echo '<p>There are currently no events on your dashboard.'; | |
| echo '</div>'; | |
| } | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment