Loading Event Data into the Post Object

Groundplan Pro includes a helper function, xdgp_load_all() that allows you to load event and performance data into your $post variable or WP_Query object with a minimum of database calls.


For a complete sample template for an event detail page, refer to this article



Usage


$args= array(
   'post_type'=> 'mc_event',
    //Parameters to include only upcoming events
);
$post_query= newWP_Query($args);
xdgp_load_all(array('query'=> $post_query, 'connections'=> true, 'connection_meta'=> true, 'connected_post_meta'=> false));  


if(!empty( $post_query->posts)) :  
  foreach($post_query->posts as$post) :  
    // Display event fields 
  endforeach; 
endif;



xdgp_load_all() Arguments


querySpecify a WP_Query query to perform the post_meta load
connections(boolean) If true, load all P2P connections (including performances) into each returned $post. For example, performances for the event will be loaded into $post→performances. Note that P2P includes basic $post information from the connected post as well, e.g. ID, post_title, post_name, etc.
connection_meta(boolean) If true, load the P2P meta for each connection. Required to access, for example, the ticket URL or performance type for a specific performance.
connected_post_meta(boolean) If true, load postmeta information for connected posts in the same database call. For complex post relationships, this can reduce database calls but may also create very large objects.
'mc_attachments'(boolean) DEPRECATED
'post'Specify a specific $post Object or post ID instead of a full query. Less efficient that the query method.
'post_type'

(text) explicitly set a post_type to load.




Note that xdgp_load_all() may not function as expected when loading queries with multiple post types in your main query, such as on a search results page. There is no limitation in the number of connected post_types.








Default Query Arguments


When you query the mc_event type, the query is by default automatically filtered to return events that need promotion: upcoming events by ascending closing date (Events that close first will display first).


You can override this default behavior by setting your own variables in the query.  This default will automatically archive closed shows, so you can modify it to create a "Past Events" layout.


$args = array(
    // set the order of returned events
    'meta_key' => 'last_date',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',


    // Filter event results
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'last_date',
            'value' => time() - (60*60*24),
            'compare' => '>'
        ),
    ), 

);






Loading the correct General Ticket URL

SINCE 1.0.14

After using xdgp_load_all() in your template, you can call the xdgp_event_general_ticket_url($event_post) function to load the ideal General Ticket URL for any "Buy Tickets" buttons on the event level.  This function returns one of three values optimized for the specifics of the event:

  • If the show is closed, the function returns false to be able to easily hide the button.
  • If the show has only one performance, the performance Ticket URL is returned to reduce clicks for the Patron while adding the event to their cart.
  • If the show has more than one performance, the General Ticket URL link is returned.



Adjust Mini Calendar to automatically open on page load 

Adapt the following jQuery code in your theme to trigger the Mini Calendar to automatically open to an appropriate date in details on page load.


$( document ).ready(function() {
  $('.xdgp-calendar-mini .day--has-events:not(.day--past)').first().click();

  $('.xdgp-calendar-mini').on('xdgp_mini_month_change_after', function(){
    $('.xdgp-calendar-mini .xdgp-calendar-mini__month__wrapper:visible .day--has-events:not(.day--past):not(.day--pad)').first().click();
  });
}