If you are using Events module on your Directory site, you have the sorting options on events category page on the top right corner before the event listing starts.
By default,it shows events listed as per Published Date (latest submitted event at the top). If you want to see events listed as per start date, you will have to select an option from top right corner.
What if you want to show events listed by Start Date by default, without having to select any sorting option?
Well, it’s easy and can be done simply by making minor code changes. Step by step, in this tutorial I will show you how to do this.
So let’s start.
We show events listing at two places in Directory site.
- Events Category Page.
- On Home Page (with T- Events listing widget).
First of all we will see how to show events sorted by “start date” on Events category page.
Events Category Page
Open a file named “event_filters.php” placed on your site at wp-content/ plugins/ Tevolution-Events/ functions/ folder.
Now go to around line: 242 in this file.
Here you can find the code as:
$orderby = " (SELECT $wpdb->postmeta.meta_value from $wpdb->postmeta where ($wpdb->posts.ID = $wpdb->postmeta.post_id) AND $wpdb->postmeta.meta_key = 'featured_c' AND $wpdb->postmeta.meta_value = 'c') DESC, $wpdb->posts.post_date DESC";
Replace it with:
$orderby = " (SELECT $wpdb->postmeta.meta_value from $wpdb->postmeta where $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key like \"st_date\") ASC";
Save and close the file.
Refresh your category page and voila! Now the events are sorted by “start date” by default on Events category page.
Now, we will do the same magic for homepage as well.
Home page:
There are two widgets that we can use to list the events on homepage with the Events add-on.
- If you are using “T-Homepage display post” widget to show the events on homepage, then please remove this widget from that widget area. And instead of “T-Homepage display post” widget use “T- Events listing” widget.
- In this widget there is an option already provided to sort events as per ‘Start date’. Select “As per Start date” option and save the settings.
Tip: Just like you were able to change default sorting to sort by date option, you can also change the default sorting to some other option given from the sorting options available on Events category page. You can follow the same procedure but just make sure to keep the variable name of the sorting option without any changes.
So by doing just a minor code change, you will now be able to show events listed according to the sorting order you prefer!
Hope it helps!