Updatam linkurile de pe WP

Am avut de mai multe ori aceasta problema, uneori am apelat la plugin-uri, alteori la copy & replace… acum am facut un mic script :

 

 

<?php

    /*
     * Se apeleaza: domeniu.tld/wp-content/themes/themename/fix.php
     * */

    $txt_old = 'old_domain.com/blog';
    $txt_new = 'new_domain.com';
    
    require '../../../wp-config.php';

    mysql_connect('localhost', DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME);
    
    $r = mysql_query('SELECT *
    FROM  `wp_posts`
    WHERE  `post_content` LIKE  "%'.$txt_old.'%"');

    $i = 0;
    while ($row = mysql_fetch_array($r)) {
        mysql_query('UPDATE wp_posts SET '.
        ' post_content = "'.addslashes(str_replace($txt_old, $txt_new, $row[‘post_content’])).'", '.
        ' guid  = "'.addslashes(str_replace($txt_old, $txt_new, $row[‘guid ‘])).'" '.
        ' WHERE ID = '.$row[‘ID’]
        );
        
        $i++;
    }
    echo "<p>Total : $i</p>";
    

    echo 'The end!';

Leave a Reply

Your email address will not be published. Required fields are marked *