Hi Stephen,
Hope you can help with this.
I need to display the number of currently available tickets after each upcoming event date on a single event page. I have created my own versions of the single-event.php and the event-meta-event-single.php files which are stored in my theme folder as recommended.
I have included my effort below. I have placed this code in the event-meta-event-single.php file as that’s where the dates are generated.
What I’m trying to achieve will look like this:
Upcoming Dates:
– 7th June, 2014 (12 spaces left)
– 20th September, 2014 (6 spaces left)
– 15th November, 2014 (3 spaces left)
However, at the moment, it’s just adding up the total number of tickets available and putting that figure after each upcoming date.
Here is my code (event-meta-event-single.php)
<
pre>
<?php if( eo_reoccurs() ){
//Event reoccurs – display dates.
$upcoming = new WP_Query(array(
‘post_type’=>’event’,
‘event_start_after’ => ‘today’,
‘posts_per_page’ => -1,
‘event_series’ => get_the_ID(),
‘group_events_by’=>’occurrence’//Don’t group by series
));
if( $upcoming->have_posts() ): ?>
<?php _e('Upcoming Dates','eventorganiser'); ?>:
<ul id="eo-upcoming-dates">
<?php while( $upcoming->have_posts() ): $upcoming->the_post(); ?>
<?php $future_occurrences = eo_get_the_future_occurrences_of( get_the_ID() );
if( $future_occurrences ){
foreach( $future_occurrences as $occurrence_id => $dates ){
$remaining = eo_get_remaining_tickets_count( get_the_ID(), $occurrence_id );
}
}
?>
<?php eo_the_start('jS F, Y') ?> <?php printf($remaining) ?>
<?php unset($remaining); ?>
<?php endwhile; ?>
Paul Oaten
Hope the above code snippet makes sense – didn’t display as expected!
Paul Oaten
Hi Paul,
No worries ;).
In the above code you are already querying future dates, and then inside that while loop getting future dates again. The foreach
loop means that $remaining
is then set to the number of remaining tickets for the last date for that event. That’s why the number comes out the same for each date.
By default the event-meta-event-single.php
template looks like this:
<li> <?php eo_the_start($date_format) ?></li>
If you change that to
<li> <?php echo eo_get_the_start($date_format) . ' (' . eo_get_remaining_tickets_count( get_the_ID(), $post->occurrence_id ).' spaces left)'; ?></li>
then that’ll print the number of tickets enxt to each date.
Stephen Harris
Perfect – thanks for the guidance!
Paul Oaten
Hi Stephen,
The line of code you refer to by default does not exist in my template php file. I would like to achieve the same results as Paul but since I cannot find that piece of code to replace with your amended code, I am stuck. Please advise.
Thanks,
Lorie
Lorie Travis