The HTML has disappeared from above
function sie_events(){
$thisDate = date("Y-m-d");
$thisDate7 = date("Y-m-d",strtotime("+1 week"));
$event_posts = event_embed()->obtain( [
'from' => $thisDate,
'to' => $thisDate7
] );
echo($thisDate . " to ". $thisDate7 . "<br />");
// Now you can iterate through the results and do // whatever you like
foreach ( $event_posts as $single_event ) {
$url = get_permalink( $single_event->ID );
$title = get_the_title( $single_event->ID );
echo 'event: <a href="' . $url . '">' . $title . '</a>';
}
}
add_shortcode('SiE_Events', 'sie_events');
Plugin Author
Barry
(@barryhughes-1)
Thanks makcooney – you’ve actually hit upon a bug here. Hold tight while I make a correction.
Plugin Author
Barry
(@barryhughes-1)
2.5.2 should be available shortly: as soon as it is, please try it out alongside your custom shortcode π
great stuff – update works
So how do I get the start date and limit to 50 please?
Thanks for your help Barry
and to be really annoying, can it be Day of week (full), date Month?
OK kinda figured it. Like I say novice.
The only part that dont work is the date_format. Maybe guidance there is possible. Thanks again for your help
function sie_events(){
$thisDate = date("Y-m-d");
$thisDate7 = date("Y-m-d",strtotime("+1 week"));
$event_posts = event_embed()->obtain( [
'from' => $thisDate,
'to' => $thisDate7,
'limit' => '50'
] );
echo($thisDate . " to ". $thisDate7 . "<br />");
// Now you can iterate through the results and do // whatever you like
foreach ( $event_posts as $single_event ) {
$url = get_permalink( $single_event->ID );
$title = get_the_title( $single_event->ID );
$datd = tribe_get_start_date( $single_event->ID, false, get_option( 'date_format', 'l j F' ) );
echo 'event: <a href="' . $url . '">' . $datd . " " . $title . '</a> <br/>';
}
}
add_shortcode('SiE_Events', 'sie_events');
Plugin Author
Barry
(@barryhughes-1)
So how do I get the start date and limit to 50 please?
The start date of each event? Use tribe_get_start_date() for that. To specify a limit just add a limit argument in the array you are passing to event_embed()->obtain() π
and to be really annoying, can it be Day of week (full), date Month?
It can be whatever you want! You can learn about date formatting in PHP (which is what tribe_get_start_date() uses under the hood) over here:
php.net/manual/en/function.date.php
Sorted π
$datd = tribe_get_start_date( $single_event->ID, false, 'l jS F' );
No need for the get_option part
Barry, your a star.