WP_Embed::delete_oembed_caches()
Deletes all oEmbed cache for the specified post.
This method has not been used in the core since version 4.0.
Also read: oEmbed in WordPress
Also see the hook: oembed_dataparse
Method of the class: WP_Embed{}
No Hooks.
Returns
null. Nothing.
Usage
global $wp_embed; $wp_embed->delete_oembed_caches( $post_id );
- $post_id(integer) (required)
- ID of the post whose oEmbed cache needs to be deleted.
Examples
#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() WP Embed::delete oembed caches code WP 6.9.1
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 );
}
}
}