Search & Remove Specific Shortcode From All Posts

Question

Is there a way to remove a specific shortcode, say [print_me] from all the posts where it appears in one shot. And I don’t mean mask it or filter it so it doesn’t show up while it stays in the post_content. I want it GONE GONE.

Attempts So Far …

So far what I have done is using phpMyAdmin, I ran a query on all post_content that appears in the table wp_posts and it shows all the posts that I was looking for but there is too many to handle individually. I ran a find/replace update query on the results trying to replace it with "" (nothing) but while the query ran successfully, so it said, I don’t see the shortcodes gone, so I am not sure if I missed something.

Here is the query I used to find them:

SELECT * FROM `wp_posts` WHERE `post_content` LIKE '%[print_me]%'

and I get 111 records. But then using the same tool to do a search and replace, I get:

Your SQL query has been executed successfully

UPDATE db1357924680.wp_posts SET post_content = REPLACE(post_content,
‘%[print_me]%’, ‘%%’) WHERE post_content LIKE ‘%%[print_me]%%’
COLLATE utf8_bin

But when you check, they are all still there. SO I am hoping someone knows a better or proper way of doing this and willing to share. If I am on the right track, then I would appreciate some assistance in figuring out why its not working as expected. TIA.

Resolution (thanks to @TheDeadMedic)

Using the corrections to my original SQL query (as follows and found in the original answer), it worked flawlessly and I accomplished what I needed, thank you.

UPDATE db1357924680.wp_posts SET post_content = REPLACE( post_content,
‘[print_me]’, ” ) WHERE post_content LIKE ‘%[print_me]%’


History (tl/rl)

I had been using a plugin for a while now that can make something appear on EVERY post and page or you could opt to only put the shortcode when you felt it was appropriate for that content.

However, after about 2 years, I gave it up in favor of a more wholesale solution that provided some other features that I wanted to incorporate in addition.

I have deactivated the plugin but now facing the problem of those shortcodes printing out as regular old text and that’s something I need to resolve.

Some environment/system information: PHP/Linux/WP_4.5.1/SQL_5.1.73/PMA_4.1.14.8

Solutions Collecting From Web of "Search & Remove Specific Shortcode From All Posts"

For the permanent solution, your SQL query is slightly off – you need:

UPDATE db1357924680.wp_posts SET post_content = REPLACE( post_content, '[print_me]', '' ) WHERE post_content LIKE '%[print_me]%' 

MySQL replace example

There is an easier way to do this:

add_filter( 'the_content', 'my_post_content_remove_shortcodes', 0 );

function my_post_content_remove_shortcodes( $content ) {

    /* Create an array of all the shortcode tags. */
    $shortcode_tags = array(
        'shortcode_1',
        'shortcode_2',
        'shortcode_3'
    );

    /* Loop through the shortcodes and remove them. */
    foreach ( $shortcode_tags as $shortcode_tag )
        remove_shortcode( $shortcode_tag );

    /* Return the post content. */
    return $content;
}

You can drop this in to your functions file.

Source: http://justintadlock.com/archives/2013/01/08/disallow-specific-shortcodes-in-post-content

–edit–

Instead of searching through your MySQL entries to remove everything, you can “remove” the shortcode’s functionality through your functions file.

The code below will filter through all of your content and remove specific shortcodes that you designate in the place marked as shortcode_1 etc.

As Mark said: This is not quite what you asked for but will give you similar results if you struggle to find something else.

Hope it helps!