Posted: October 11, 2013 at 1:01 pm
|
I found a great resource for creating a page that lists only past events I am using most current version of WordPress and Event Espresso |
|
Hi, The $pastevent is an array of the event details, so you can echo/add $pastevent->start_date eg <?php /* Template Name: Past Events */ ?> <ul> <?php global $wpdb; $tablename = $wpdb->prefix . events_detail; $pastevents = $wpdb->get_results("SELECT * FROM $tablename WHERE start_date < curdate() AND event_status <> 'D' "); foreach ( $pastevents as $pastevent ){ echo '<li><a href="' . espresso_reg_url($pastevent->id) . '">' . stripslashes($pastevent->event_name) . ' - ' . $pastevent->start_date . '</a></li>'; } ?> </ul> I haven’t tested it, but you will probably need to reformat the date as it is likely to spit it out like 2013-10-14. date(‘d-m-Y’, $pastevent->start_date) should work, see here for more info http://php.net/manual/en/function.date.php |
|
Thanks Dean |
|
Got it! the code I wanted is actually |
|
Oops! Right formatting but it reverts to a date of something like January 1, 1969 and not the date of the event. Guess I could use your help after all. Any idea how to correctly write the PHP for this? |
php date() needs a string or a timestamp in order to work. In this case you can use date_create and date_format. Here’s a revised loop that displays the date using date_create and date_format: foreach ( $pastevents as $pastevent ){ $my_event_date = date_create($pastevent->start_date); echo '<li><a href="' . espresso_reg_url($pastevent->id) . '">' . stripslashes($pastevent->event_name) . ' - ' . date_format($my_event_date, 'F j, Y' ) .'</a></li>'; } |
|
|
Thanks Josh |
The support post ‘Modifying Past Events page’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.