[wp-hackers] How to Exclude shortcode in databse

Chris McCoy chris at lod.com
Thu Jul 12 05:16:32 UTC 2012


Kinda hacky way of doing it, but here is something I did a while back

function remove_shortcode_from_db($shortcode = 'button') {

    global $wpdb;

    $posts = $wpdb->get_results("SELECT ID,post_title,post_content FROM
$wpdb->posts");
    $regex =
'/\[(\[?)('.$shortcode.')\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([
^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/s';

    foreach($posts as $post) {
        $final = preg_replace($regex,'',$post->post_content);
        $change = $wpdb->update( $wpdb->posts, array('post_content' =>
$final), array('ID' => $post->ID));
    }
}

Will accept any parameter being atgallery will look for all attribs and
remove

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Diana K. C
Sent: Wednesday, July 11, 2012 10:21 PM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] How to Exclude shortcode in databse

That't quick I think:

I found some SQL commands around, but all deal with fix shortcodes like
[tweet], I need to exlcude shortcodes like [atgallery id="144"], [tagellery
= "12"] etc

Thanks for help!
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list