Title: WP_Community_Events::get_cached_events
Published: June 15, 2017
Last modified: April 28, 2025

---

# WP_Community_Events::get_cached_events(): array|false

## In this article

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

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

Gets cached events.

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

 array|false An array containing `location` and `events` items on success, false
on failure.

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

    ```php
    public function get_cached_events() {
    	$transient_key = $this->get_events_transient_key( $this->user_location );
    	if ( ! $transient_key ) {
    		return false;
    	}

    	$cached_response = get_site_transient( $transient_key );
    	if ( isset( $cached_response['events'] ) ) {
    		$cached_response['events'] = $this->trim_events( $cached_response['events'] );
    	}

    	return $cached_response;
    }
    ```

[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#L355)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-community-events.php#L355-L367)

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

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

Prepares the event list for presentation.

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

Generates a transient key based on user location.

  | 
| [get_site_transient()](https://developer.wordpress.org/reference/functions/get_site_transient/)`wp-includes/option.php` |

Retrieves the value of a site transient.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_community_events/get_cached_events/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_community_events/get_cached_events/?output_format=md#)

| 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.

  |

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

| Version | Description | 
| [5.5.2](https://developer.wordpress.org/reference/since/5.5.2/) | Response no longer contains formatted date field. They’re added in `wp.communityEvents.populateDynamicEventFields()` now. | 
| [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%2Fget_cached_events%2F)
before being able to contribute a note or feedback.