Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active October 14, 2019 11:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/c1f355e2528a9e71beb7e4ddef61b6af to your computer and use it in GitHub Desktop.
Save billerickson/c1f355e2528a9e71beb7e4ddef61b6af to your computer and use it in GitHub Desktop.
[display-posts post_type="ai1ec_event"]
<?php
/**
* Display Posts - All in One Event Calendar
* @see https://wordpress.org/support/topic/support-for-all-in-one-event-calendar/
*
* @param array $args, query arguments
* @param array $atts, shortcode attributes
* @return array $args, modified query arguments
*/
function be_dps_ai1ec( $args, $atts ) {
if( empty( $args['post_type'] ) || 'ai1ec_event' !== $args['post_type'] )
return $args;
// This function is in the plugin. If it can't be found, plugin isn't active so return early
if( ! function_exists( 'ai1ec_return_false' ) )
return $args;
global $ai1ec_calendar_helper, $ai1ec_events_helper;
// gets localized time
$bits = $ai1ec_events_helper->gmgetdate( $ai1ec_events_helper->gmt_to_local( time() ) );
//sets start time to today
$start = gmmktime(0,0,0,$bits['mon'],$bits['mday'],$bits['year']);
//sets end time to a year from today i.e. $bits['year']+1
$end = gmmktime(0,0,0,$bits['mon'],$bits['mday'],$bits['year']+1);
//Look in class-ai1ec-calendar-helper.php for details
$get_events = $ai1ec_calendar_helper->get_events_between($start,$end);
foreach($get_events as $event ):
$post_ids[] = $event->post_id;
endforeach;
$args['post__in'] = $post_ids;
$args['orderby'] = 'post__in';
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_dps_ai1ec', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment