cliff
6/24/2016 - 5:50 PM

Wipe all stored oEmbeds from WordPress database

Wipe all stored oEmbeds from WordPress database

<?php

/**
 * 
 * Warning: If you do NOT follow step #3, your site will be significantly less efficient than it should be!
 * 
 * 1. add this code to your theme's functions.php file
 * 2. load a page on the front-end of your site (e.g. the home page)
 * 3. comment out or delete this code from your theme's functions.php file
 * 4. check to see if previously incorrect oEmbeds are now fixed (i.e. visit a page that had one and see if the oEmbed is now displaying correctly)
 * 
 * 
 * From https://gist.github.com/cliffordp/e331b28d0d4d3b042fc7daf714256796
 * 
 */

function wipe_oembed_postmeta() {
    global $wpdb;

    $wpdb->query( "
        DELETE 
        FROM   $wpdb->postmeta
        WHERE  meta_key LIKE '_oembed_%'
    " );
}

add_action( 'init', 'wipe_oembed_postmeta' );