Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

share|improve this question
add comment

1 Answer 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'
        )
);
share|improve this answer
    
Do I have to fill up UPDATE <YOUR_PREFIX_HERE>? and what is it? –  user31445 Apr 13 '13 at 12:02
    
I put the sql query but I've got this error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<YOUR_PREFIX_HERE>_posts SET post_content = replace(post_content, 'www.lol.com/?' at line 1 –  user31445 Apr 13 '13 at 12:04
    
You just have to set <YOUR_PREFIX_HERE> to your WP table prefix. Normally, this is wp, however, you may have changed that to something else. You can see this either in your database (all WP tables have the same prefix), or in your wp-config.php file. –  t f Apr 13 '13 at 12:05
1  
You can use "UPDATE {$wpdb->posts} SET post_content = ..." or "UPDATE {$wpdb->prefix}posts SET post_content = ..." . –  birgire Apr 13 '13 at 12:24
    
Thank you very muchh, both method worked –  user31445 Apr 13 '13 at 12:26
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.