Title: WP_Community_Events::trim_events
Published: June 15, 2017
Last modified: February 24, 2026

---

# WP_Community_Events::trim_events( array $events ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#wp--skip-link--target)

Prepares the event list for presentation.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#description)󠁿

Discards expired events, and makes WordCamps “sticky.” Attendees need more advanced
notice about WordCamps than they do for meetups, so camps should appear in the list
sooner. If a WordCamp is coming up, the API will “stick” it in the response, even
if it wouldn’t otherwise appear. When that happens, the event will be at the end
of the list, and will need to be moved into a higher position, so that it doesn’t
get trimmed off.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#parameters)󠁿

 `$events`arrayrequired

The events that will be prepared.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#return)󠁿

 array The response body with events trimmed.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#source)󠁿

    ```php
    protected function trim_events( array $events ) {
    	$future_events = array();

    	foreach ( $events as $event ) {
    		/*
    		 * The API's `date` and `end_date` fields are in the _event's_ local timezone, but UTC is needed so
    		 * it can be converted to the _user's_ local time.
    		 */
    		$end_time = (int) $event['end_unix_timestamp'];

    		if ( time() < $end_time ) {
    			// Decode HTML entities from the event title.
    			$event['title'] = html_entity_decode( $event['title'], ENT_QUOTES, 'UTF-8' );

    			array_push( $future_events, $event );
    		}
    	}

    	$future_wordcamps = array_filter(
    		$future_events,
    		static function ( $wordcamp ) {
    			return 'wordcamp' === $wordcamp['type'];
    		}
    	);

    	$future_wordcamps    = array_values( $future_wordcamps ); // Remove gaps in indices.
    	$trimmed_events      = array_slice( $future_events, 0, 3 );
    	$trimmed_event_types = wp_list_pluck( $trimmed_events, 'type' );

    	// Make sure the soonest upcoming WordCamp is pinned in the list.
    	if ( $future_wordcamps && ! in_array( 'wordcamp', $trimmed_event_types, true ) ) {
    		array_pop( $trimmed_events );
    		array_push( $trimmed_events, $future_wordcamps[0] );
    	}

    	return $trimmed_events;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-community-events.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-community-events.php#L462)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-community-events.php#L462-L498)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_list_pluck()](https://developer.wordpress.org/reference/functions/wp_list_pluck/)`wp-includes/functions.php` |

Plucks a certain field out of each object or array in an array.

  |

| Used by | Description | 
| [WP_Community_Events::get_events()](https://developer.wordpress.org/reference/classes/wp_community_events/get_events/)`wp-admin/includes/class-wp-community-events.php` |

Gets data about events near a particular location.

  | 
| [WP_Community_Events::get_cached_events()](https://developer.wordpress.org/reference/classes/wp_community_events/get_cached_events/)`wp-admin/includes/class-wp-community-events.php` |

Gets cached events.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_community_events/trim_events/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Decode HTML entities from the event title. | 
| [5.5.2](https://developer.wordpress.org/reference/since/5.5.2/) | Accepts and returns only the events, rather than an entire HTTP response. | 
| [4.9.7](https://developer.wordpress.org/reference/since/4.9.7/) | Stick a WordCamp to the final list. | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_community_events%2Ftrim_events%2F)
before being able to contribute a note or feedback.