Support » Fixing WordPress » Removing broken shortcodes

  • Resolved cagsmith


    Hi all,

    I wonder if this question may be out of scope for this particular forum, but I figured I could ask anyway. I used to have an Amazon Associates plugin which would help me insert locale-specific Amazon links to products with the help of a shortcode. Unfortunately, the developer ceased work on this plugin a long time ago and it seems to be encountering errors with this version of WordPress (causing php errors to be thrown).

    What I want to do is remove all these shortcodes – *actually* delete them, and not just hide them with the help of a plugin (seems to me that that method is like sticking a band-aid on without actually fixing the root issue). The problem is that each shortcode contains an ID which is different. Every shortcode takes the format of:

    [amazon_link id=”XXXXXXXX” target=”_blank” ]Text Here[/amazon_link]

    where “XXXXXXXX” is a different Amazon product ID.

    What I’m after is some sort of SQL query which will help me remove these bad shortcodes directly from the post_content column in wp_posts table. Seems that you can’t use wildcards using UPDATE statement alas.

    Does anyone know a way? Thanks all!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ok, for what it’s worth, I dumped the table into Notepad++ and used some regex to extract the link IDs. As a result I’ve been able to come up with a whole load of statements looking like this:

    UPDATE 'wp_posts' SET 'post_content' = REPLACE ('post_content', '[amazon_link id="B0001IX3MS" target="_blank" ]', '';
    UPDATE 'wp_posts' SET 'post_content' = REPLACE ('post_content', '[amazon_link id="B0001IX3R8" target="_blank" ]', '';
    UPDATE 'wp_posts' SET 'post_content' = REPLACE ('post_content', '[amazon_link id="B0001IX454" target="_blank" ]', '';

    But I’m getting a syntax error in PhpMyAdmin when attempting to run these… anyone have any idea?

    Ok, never mind – I’m an idiot… forgot the closing bracket!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Removing broken shortcodes’ is closed to new replies.