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

2 Answers
2

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

Leave a Comment