Last active
October 14, 2019 11:46
-
-
Save billerickson/c1f355e2528a9e71beb7e4ddef61b6af to your computer and use it in GitHub Desktop.
[display-posts post_type="ai1ec_event"]
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 | |
/** | |
* 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