Support

Home Forums Event Espresso Premium function of archived events?

function of archived events?

Posted: January 21, 2016 at 5:42 am


Meredith Whitely

January 21, 2016 at 5:42 am

I can’t find what the function that returns an array of IDs of archived events would be?
Anyone know?


Tony

  • Support Staff

January 21, 2016 at 6:04 am

Hi Meredith,

Can you explain this further please, what do you mean be archived events?


Meredith Whitely

January 21, 2016 at 7:37 am

I’m looking to use SearchWP to search for just events. However, past events also appear at the moment, and they have this custom function (see below) to exclude certain things, and I’m looking to exclude the past archive events, but I can’t see what the taxonomy would be to add in the code below to replace the ids. Any ideas?

<?php
 
function my_searchwp_exclude( $ids, $engine, $terms )
{
  $ids[] = 78; // forcefully exclude post 78
  return $ids;
}
 
add_filter( 'searchwp_exclude', 'my_searchwp_exclude', 10, 3 );


Tony

  • Support Staff

January 22, 2016 at 4:59 am

With Event Espresso there are no archived events in the way described above. There is no taxonomy to add that will exclude expired events, you need to manually pull in the IDs by querying for all events that have the Datetime end date set in the past (compared with today’s date).

Something like this:

https://gist.github.com/Pebblo/67b9d4587b6e4810721a

Should pull in all of the expired events ID’s from within EE.

Note however the code in that gist is intended as an example as is not heavily tested nor supported.


Meredith Whitely

January 27, 2016 at 9:46 am

Thanks, this worked great.

Here was the final function for SearchWP.

// Excludes archived events
function my_searchwp_exclude( $ids, $engine, $terms ) {
	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)
		$ids = array_merge( $ids, $expired_event_ids );
		$ids = array_unique( $ids );
	}
	return $ids;
}
add_filter( 'searchwp_exclude', 'my_searchwp_exclude', 10, 3 );


Josh

  • Support Staff

January 27, 2016 at 1:36 pm

Thanks for sharing, I’m going to tag this.

The support post ‘function of archived 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