WP_Embed::delete_oembed_caches()publicWP 1.0

Delete all oEmbed caches. Unused by core as of 4.0.0.

Method of the class: WP_Embed{}

No Hooks.

Return

null. Nothing (null).

Usage

global $wp_embed;
$wp_embed->delete_oembed_caches( $post_id );
$post_id(int) (required)
Post ID to delete the caches for.

Examples

0

#1 Example of removing the oEmbed cache for a specified post

$post_id = 8045;

// see the meta-fields before deletion
print_r( get_post_meta( $post_id ) );

// delete
$GLOBALS['wp_embed']->delete_oembed_caches( $post_id );

// see the meta-fields after deletion
print_r( get_post_meta( $post_id ) );

WP_Embed::delete_oembed_caches() code WP 6.5.2

public function delete_oembed_caches( $post_id ) {
	$post_metas = get_post_custom_keys( $post_id );
	if ( empty( $post_metas ) ) {
		return;
	}

	foreach ( $post_metas as $post_meta_key ) {
		if ( str_starts_with( $post_meta_key, '_oembed_' ) ) {
			delete_post_meta( $post_id, $post_meta_key );
		}
	}
}