If the plugin detects that there is a custom post type registered with a particular name (either ‘event’ or ‘*_event’), it steps in and does a number of useful additional things:
- For front-end queries fetching events, returned posts are sorted chronologically, the oldest first.
- For front-end queries fetching events, by default only future events are returned. This can be overridden by setting the custom parameter
slt_all_eventsin your posts query to
true. Alternatively, use
true) to get only past events.
- By default the current time is used to compare dates for selecting past or future events. To change the time used for the cut-off, use the filter
slt_se_listing_time_offset. It defaults to
0(no change from the current time). To set the cut-off to 24 hours ahead of the current time, hook a function to this filter that returns that value in seconds, i.e.
60 * 60 * 24.
- By default events are ordered chronologically. To reverse the order, set
- In the admin listing page for events, an ‘Event date’ column is added.
- For particular queries, all actions performed by this plugin can be disabled by setting the custom parameter
disable_simple_eventsin your posts query to
IMPORTANT: The automatic event filtering only kicks in with front-end queries done using
WP_Query. Use this rather than
In addition, this function is provided for convenience. If an event date exists for the post in question, it returns that; if not, it returns the standard post date.
<?php slt_se_get_date( $the_post = null ) ?>
- $the_post (object) (optional) (default: global $post object)
NOTE: An Event Date custom field will be added to the event edit screen automatically if my Custom Fields plugin is active. Otherwise, make sure your event post type supports
[register_post_type](https://codex.wordpress.org/Function_Reference/register_post_type), and add dates to events with the format YYYY/MM/DD, e.g. 2011/12/21 – this format is required to allow sorting by this field.
NOTE: The filtering performed by this plugin currently doesn’t work well with
get_posts – for now, create custom loops with
Development code hosted at GitHub.
- Upload the
simple-eventsdirectory into the
- Activate the plugin through the ‘Plugins’ menu in WordPress
Contributors & Developers
“Simple Events” is open source software. The following people have contributed to this plugin.Contributors
- Fixed bug in
- More tests for Developer’s Custom Fields functions
- Set the priority of the init action very low so that any custom post types are definitely registered first (thanks lowe_22!)
slt_se_get_dateso the call to
slt_cf_field_valueworks when a post object is passed
- Corrected mistake in adding admin listing event date column, needed to use post type in filter name
- Added a test for whether the query is singular – previously the hooks were preventing the display of past event singular pages
disable_simple_eventsparameter for posts queries
- Added function to consolidate tests for whether a hook should be applied
- Changed order in
ASC(nearest upcoming events first in list)
- Changed detection of event post type to “event” or “*_event”
- Changed date format to allow proper sorting
posts_wherefilters for WP 3.1.1+ – doesn’t seem to be necessary
- First version