Automaticly replace a link with other “new link”

I want “a link” in my content “automaticly” replace with “new link”

Heres the explanation, in my all post content I want a link of www.lol.com/?http:/rapidshare.com automaticly replace with new link http://rapidshare.com

Read More

Whats the code to add in my functions.php ?? or any plugin that automaticly replace that old link with new one?

Related posts

Leave a Reply

1 comment

  1. This is the SQL:

    UPDATE <YOUR_PREFIX_HERE>_posts SET post_content = replace(post_content, 'www.lol.com/?http://rapidshare.com', 'http://rapidshare.com');
    

    Either inject it directly into the database (via PHPmyAdmin and the like) or use WordPress to do so.

    Here’s the WordPress way:

    global $wpdb;
    $wpdb->query(
        $wpdb->prepare(
            "UPDATE <YOUR_PREFIX_HERE>_posts
            SET post_content = replace(post_content, %s, %s)",
            'www.lol.com/?http://rapidshare.com',
            'http://rapidshare.com'
            )
    );
    

    // EDIT
    For completeness (as @birgire suggested): if you don’t know the table prefix, you can let WordPress look that up:

    global $wpdb;
    $wpdb->query(
        $wpdb->prepare(
            "UPDATE {$wpdb->posts}
            SET post_content = replace(post_content, %s, %s)",
            'www.lol.com/?http://rapidshare.com',
            'http://rapidshare.com'
            )
    );