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' );
@petrab
Copy link

petrab commented Jan 29, 2015

Hello Lukas,
thank you for this code. I'm glad I found it. However, the timestamp seems to be ignored. It always shows me only future events, even when I change the timestamp to the past. Maybe my understanding of the plugin functions is to limited. In case you have any pointers for me how to get the code to show also past events, I would be grateful for them. In any case, thank you very much for your work.
Kind regards, Petra

@karissademi
Copy link

This gist is one of the most helpful things on the internet, ever. Thank you so much.

@somenamethatisnttaken
Copy link

Thanks for posting this. I'm having issues with the $post_title = $instance->get( 'post' )->post_title; part of this. Fatal error: Call to a member function get() on a non-object.

I've done a dump on $instance and i see all values I need but can't seem to call them.

Thoughts?

@Susa38
Copy link

Susa38 commented Jan 26, 2016

thanks a lot.
One question.
Is not possible to show the post feature image?

@nelero
Copy link

nelero commented Dec 12, 2016

@somenamethatisnttaken : it seems that for now, it's not an object but an array which is returned by A1ec.
So i had to add $post = get_post($instance['post_id']);
and replace $instance->get( 'post' ) by $post for code after

@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