• Home
  • Knowledgebase
  • DevDocs
  • Translations
  • Support
  • Live Preview

logo DevDocs

By The Events Calendar
Filter by type:
Skip to content
Filter by type:
Search
Browse: Home / Classes / Provisional_Post_Meta / Provisional_Post_Meta::hydrate_tec_occurrence_meta()
Product: The Events Calendar PRO

Provisional_Post_Meta::hydrate_tec_occurrence_meta( mixed $meta_value, int $object_id, string $meta_key )

Hooks on the request to get the post metadata to hydrate the post caches.

Contents

  • Parameters
  • Return
  • Source
  • Changelog

This method is specially important in the context of those calls to get_post for a provisional ID followed by a check of the _tec_occurrence property. The WP_Post::__get method will check the meta, thus triggering this method, and will allow the provisional post caches to be set up correctly, including the _tec_occurrence property.


Parameters

$meta_value

(mixed) (Required) The value of the meta.

$object_id

(int) (Required) The ID of the post the meta is for.

$meta_key

(string) (Required) The meta key.


Top ↑

Return

(mixed) The value of the meta, unmodified by this code.


Top ↑

Source

File: src/Events_Pro/Custom_Tables/V1/Models/Provisional_Post_Meta.php

	public function hydrate_tec_occurrence_meta( $meta_value, int $object_id, string $meta_key ) {
		if ( $meta_key !== '_tec_occurrence' ) {
			return $meta_value;
		}

		$provisional = tribe( Provisional_Post::class );

		if ( ! $provisional->is_provisional_post_id( $object_id ) ) {
			return $meta_value;
		}

		$post = get_post( $object_id );
		// Maybe already hydrated? Use `get_object_vars` as `isset` will trigger the `WP_Post::__get` method.
		$occurrence_id = get_object_vars( $post )['_tec_occurrence_id'] ?? null;

		if ( empty( $occurrence_id ) ) {
			// Not already hydrated, let's do it now.
			$provisional->hydrate_caches( [ $object_id ] );

			// Avoid using a method that will either hit the database or cause another `get_post_meta` call.
			$occurrence_id = get_object_vars( $post )['_tec_occurrence_id'] ?? null;
		}

		if ( empty( $occurrence_id ) ) {
			return $meta_value;
		}

		// Attempt to fetch from memoized cache.
		$cache_key = 'event_occurrence_' . $occurrence_id;
		$cache     = tribe_cache();

		// Check if we already memoized this.
		if ( $cache[ $cache_key ] instanceof Occurrence ) {
			return $cache[ $cache_key ];
		}

		// Could not be found in memory, fetch again.
		$occurrence = Occurrence::find( $occurrence_id, 'occurrence_id' );

		if ( $occurrence instanceof Occurrence ) {
			$cache[ $cache_key ] = $occurrence;

			return $occurrence;
		}

		return $meta_value;
	}

Expand full source code Collapse full source code


Top ↑

Changelog

Changelog
Version Description
7.3.0 Moved from Provisional_Post
6.0.0 Introduced.
The Events Calendar
  • Home
  • Products
  • Blog
  • Support
© 2026 The Events Calendar Terms and Conditions Privacy