Support

Home Forums Event Espresso Premium "Order by" for past events

"Order by" for past events

Posted: June 2, 2014 at 12:45 am

Viewing 2 reply threads


Jason Lee

June 2, 2014 at 12:45 am

Hi there,

I’m using some php I found in the forums to show past events on a page on my site. It is working great but I would like to have them sorted with newest first. I found a thread on that telling what to add but I don’t know exactly where in the php to add it as I know minimal about it.

This is the php I found…

<?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 ‘id) . ‘”>’ . stripslashes($pastevent->event_name) . ‘‘;
}
?>

And this is what I found to add…

ORDER BY date(start_date) DESC

Just not sure where or exactly how to add. Slowly learning this stuff πŸ™‚


Jason Lee

June 2, 2014 at 12:46 am

Also, is there possibly a way to not show duplicates (events with the same title)?

Thanks!


Dean

June 2, 2014 at 5:16 am

Hi,

Try this

global $wpdb;
$tablename = $wpdb->prefix . events_detail;
$pastevents = $wpdb->get_results("SELECT * FROM $tablename WHERE start_date < curdate() AND event_status <> 'D' ORDER BY date(start_date) DESC");
foreach ( $pastevents as $pastevent ){
echo stripslashes($pastevent->event_name) . "<br>";
}

This line

echo β€˜id) . β€˜β€>’ . stripslashes($pastevent->event_name) . β€˜β€˜;

was broken, wasn’t sure what you were trying to achieve, so I edited it just to output the event name followed by a line break.

Regarding the duplicates, you would probably want to use something like this http://stackoverflow.com/questions/16380868/removing-duplicate-array-from-an-array-of-arrays

Viewing 2 reply threads

The support post ‘"Order by" for past events’ 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.

Event Espresso