Production site contains links from staging site after WordPress synchronization via WordPress Toolkit

Follow

Comments

2 comments

  • Avatar
    Ehud Ziegelman

    Hi Marc Vidal ,

    The problems seems not to be ralted to cache as presented in the solution. I'm afraid clearing cache is NOT the solution.

    See a simillar problem:

    https://support.plesk.com/hc/en-us/articles/360015830933--BUG-After-synchronizing-or-cloning-WordPress-instance-via-WordPress-Toolkit-in-Plesk-few-URLs-in-target-instance-point-to-source-WordPress-instance

     

    A code on comments of a Yoast Plugin article, may be a temp solution

    https://developer.yoast.com/blog/relative-urls-issues/

     

    <code>

    <?php
    $user="username";
    $password="password";
    $database="database";
    mysql_connect(localhost,$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");
     
    $oldurl = "dev.choiceomg.com";
    $newurl = "www.choiceomg.com";
     
    $query = "SELECT post_content, id from wp_posts where post_content LIKE '%$oldurl%'";
    $result = mysql_query($query);
    $num=mysql_numrows($result);
     
    $i=0;
    while ($i < $num) {
     
        $id = mysql_result($result, $i ,"id");
        $post_content =mysql_result($result,$i,"post_content");
        $post_content = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $post_content));
         
        $q = "UPDATE wp_posts set post_content = '$post_content' where id = $id";
        //var_dump($q);
        mysql_query($q);
         
        $i++;
         
    }
     
    $query = "SELECT guid, id from wp_posts where guid LIKE '%$oldurl%'";
    $result = mysql_query($query);
    $num=mysql_numrows($result);
     
    $i=0;
    while ($i < $num) {
     
        $id = mysql_result($result, $i ,"id");
        $post_content =mysql_result($result,$i,"guid");
        $post_content = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $post_content));
         
        $q = "UPDATE wp_posts set guid = '$post_content' where id = $id";
        //var_dump($q);
        mysql_query($q);
         
        $i++;
         
    }
     
    $query = "SELECT meta_id, meta_value from wp_postmeta where meta_value LIKE '%$oldurl%'";
    $result = mysql_query($query);
    $num=mysql_numrows($result);
     
    $i=0;
    while ($i < $num) {
     
        $id = mysql_result($result, $i ,"meta_id");
        $post_content =mysql_result($result,$i,"meta_value");
        // check if it's serialized
        $post_arr = unserialize($post_content);
        if ($post_arr === false)
            $post_content = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $post_content));
        else {
            // its unserializable, iterate through all of array and replace each item
            foreach ($post_arr as $key => &$item) {
                $item = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $item));
            }
             
            $post_content = serialize($post_arr);
         
        }
        $q = "UPDATE wp_postmeta set meta_value = '$post_content' where meta_id = $id";
        //var_dump($q);
        mysql_query($q);
         
        $i++;
         
    }
     
    $query = "SELECT option_id, option_value from wp_options where option_value LIKE '%$oldurl%'";
    $result = mysql_query($query);
    $num=mysql_numrows($result);
     
    var_dump($num);
    $i=0;
    while ($i < $num) {
     
        $id = mysql_result($result, $i ,"option_id");
        $post_content =mysql_result($result,$i,"option_value");
        // check if it's serialized
        $post_arr = unserialize($post_content);
        if ($post_arr === false)
            $post_content = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $post_content));
        else {
            // its unserializable, iterate through all of array and replace each item
            foreach ($post_arr as $key => &$item) {
                $item = mysql_real_escape_string(preg_replace("/$oldurl/", "$newurl", $item));
            }
             
            $post_content = serialize($post_arr);
         
        }
        $q = "UPDATE wp_options set option_value = '$post_content' where option_id = $id";
        mysql_query($q);
         
        $i++;
    }

    </code>

    0
    Comment actions Permalink
  • Avatar
    Ehud Ziegelman

    Hi Marc Vidal ,

     

    Please note I had to click CANCLE in order to get instance ID numbers, and that script did NOT finish running on its own.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request