WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Removing broken shortcodes (3 posts)

  1. cagsmith
    Member
    Posted 1 year ago #

    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!

  2. cagsmith
    Member
    Posted 1 year ago #

    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?

  3. cagsmith
    Member
    Posted 1 year ago #

    Ok, never mind - I'm an idiot... forgot the closing bracket!

Topic Closed

This topic has been closed to new replies.

About this Topic