Skip to content

Instantly share code, notes, and snippets.

@lukaspawlik
Last active May 15, 2021 05:49
Show Gist options
  • Save lukaspawlik/045dbd5b517a9eb1cf95 to your computer and use it in GitHub Desktop.
Save lukaspawlik/045dbd5b517a9eb1cf95 to your computer and use it in GitHub Desktop.
AI1EC usage sample
function ai1ec2_display_events_func( $atts ) {
global $ai1ec_registry;
$content = '<div id="content2"><img src="/wp-content/themes/scio/images/events-header.png" alt="" />';
$time = $ai1ec_registry->get( 'date.system' );
// Get localized time
$timestamp = $time->current_time();
// Set $limit to the specified categories/tags
$limit = array(
//
// this is demo data - please use your own filters
//
'tag_ids' => array ( 29 )
);
$events_per_page = 2;
$paged = 0;
$event_results = $ai1ec_registry->get( 'model.search' )
->get_events_relative_to(
$timestamp,
$events_per_page,
$paged,
$limit
);
$dates = $ai1ec_registry->get(
'view.calendar.view.agenda',
$ai1ec_registry->get( 'http.request.parser' )
)->get_agenda_like_date_array( $event_results['events'] );
foreach ( $dates as $date ) {
foreach ( $date['events']['allday'] as $instance ) {
$post_title = $instance->get( 'post' )->post_title;
$post_name = $instance->get( 'post' )->post_name;
$post_content = $instance->get( 'post' )->post_content;
$instance_id = $instance->get( 'instance_id' );
$content .= '<div class="hp-event">
<a href="ai1ec_event/'.$post_name.'/?instance_id='.$instance_id.'">'
.$post_title.'</a><br />'
.$post_content.
'<a class="read-more-link" href="ai1ec_event/'.$post_name.'/?instance_id='.$instance_id.'">read more</a>
</div>';
}
foreach ( $date['events']['notallday'] as $instance ) {
$post_title = $instance->get( 'post' )->post_title;
$post_name = $instance->get( 'post' )->post_name;
$post_content = $instance->get( 'post' )->post_content;
$instance_id = $instance->get( 'instance_id' );
$content .= '<div class="hp-event">
<a href="ai1ec_event/'.$post_name.'/?instance_id='.$instance_id.'">'
.$post_title.'</a><br />'
.$post_content.
'<a class="read-more-link" href="ai1ec_event/'.$post_name.'/?instance_id='.$instance_id.'">read more</a>
</div>';
}
}
$content .= '</div>';
return $content;
}
add_shortcode( 'display_events2', 'ai1ec2_display_events_func' );
@gregthrive
Copy link

@nelero - Can you elaborate on your comment? I'm not quite following-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment