Last active
January 22, 2016 11:58
-
-
Save Pebblo/67b9d4587b6e4810721a to your computer and use it in GitHub Desktop.
A function used to pull all of the expired events ids from EE.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
if ( class_exists( 'EE_Registry' ) ) { | |
$exclude_query[0] = array( 'Datetime.DTT_EVT_end' => array( '>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ) ); | |
//first get all events that have datetimes where its not expired. | |
$exclude_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' ); | |
$exclude_event_ids = array_keys( $exclude_event_ids ); | |
//Grab all events where the Datetime end date is less than today (expired) excluding the events we pulled in above. | |
$where_params['AND'] = array( | |
'Datetime.DTT_EVT_end' => array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ), | |
'EVT_ID' => array( 'NOT IN', $exclude_event_ids ) | |
); | |
$query_params[0] = $where_params; | |
$expired_event_ids = EE_Registry::instance()->load_model( 'Event' )->get_all_wpdb_results( $query_params, OBJECT_K, 'Event_CPT.ID' ); | |
$expired_event_ids = array_keys( $expired_event_ids ); | |
//$expired_event_ids is now an array containing the ID's of the expired events. | |
//If using Kint debugger you can view this using: | |
//d($expired_event_ids); | |
//Otherwise just: | |
//var_dump($expired_event_ids) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment