Developers can make custom queries to the MusicIDB Calendar.
First check to see if you are connect to the MusicIDB API
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
use MusicIDB\Client\Api_Exception;
use MusicIDB\Client\MusicIDB_API;
$settings = get_option('musicidb_options');
$connected = !empty( $settings['musicidb_api_connected'] ) ? $settings['musicidb_api_connected'] : 0;
if ($connected) {
}
This next block of code gets the instance of the MusicIDB plugin, sends $args through the MusicIDB_API event filter_query and catches any API errors.
The venue key takes an array of strings as the venue ID.
$musicidb_plugin = MusicIDBIntegration::get_instance();
try {
$args = array(
'is_published' => true,
'limit' => $limit,
'is_delete' => false,
'is_featured' => true,
'venues' => $venue_ids,
'start_date_after' => current_time( 'Y-m-d' ),
'order_direction' => 'ASC'
);
$response = MusicIDB_API::request( 'event', 'filter_query', $args );
$events = array();
if( 200 === $response->get_status() ) {
$events = $response->get_events();
}
} catch( Api_Exception $e ) {
error_log( $e->getMessage() ); ?>
<li>
<p>Sorry we're having trouble loading the events right now...
<?php if( defined( 'WP_DEBUG' ) && WP_DEBUG ): ?><br />Encountered an error: <?php esc_html_e( $e->getMessage() ); ?><?php endif; ?>
</p>
</li>
<?php
}
This block of code checks to see if the number of events returned is less than the limit set, and if so grabs the next non-featured events while avoiding duplicates. This is optional and can be added to the Try statement from above
if( count($events) < $limit ) {
// Handle remainder when there aren't enough
// featured events. This uses filter_query
// to avoid dupes
$remainder = $limit - count($events);
$args = array(
'is_published' => true,
'limit' => $remainder,
'is_delete' => false,
'is_featured' => false,
'venues' => $venue_ids,
'start_date_after' => current_time( 'Y-m-d' ),
'order_direction' => 'ASC'
);
$upcoming_response = MusicIDB_API::request( 'event', 'filter_query', $args );
if( 404 === $upcoming_response->get_status() ) {
$upcoming = array();
} else {
$upcoming = $upcoming_response->get_events();
}
$events = array_merge( $events, $upcoming );
}
If no events are found display the no events message, else use a foreach loop to iterate through each event
if( empty($events) ){ ?>
<p><?php echo $settings['musicidb_no_event_msg']; ?></p>
<?php } else {
foreach( $events as $event ){
}
}
Here are some examples of the functions available to get information about the event
get_subtitle(); get_thumbnail(); get_poster(); get_ticket_link(); get_ticket_price(); get_door_cover(); get_more_info(); get_age_restriction(); get_date(); get_is_featured(); get_name(); get_venue();
Here is an example of how to retrieve the event venue information
foreach( $events as $event ){
$venue = $event->get_venue();
$venue_address = $venue->get_address();
$venue_street = $venue_address->get_address();
$venue_city = $venue_address->get_city();
$venue_state = $venue_address->get_state();
}