Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. include 'wp-config.php';
  3.  
  4. $servername = DB_HOST;
  5. $username = DB_USER;
  6. $password = DB_PASSWORD;
  7. $dbname = DB_NAME;
  8.  
  9. $old_url = "";
  10. $new_url = "";
  11.  
  12.  
  13. if ( !empty($old_url) && !empty($new_url) ) {
  14.  
  15. $conn = new mysqli( $servername, $username, $password, $dbname );
  16. if ( $conn->connect_error ) {
  17. die( "Connection failed: " . $conn->connect_error );
  18. }
  19.  
  20. $sql_options = "UPDATE wp_options SET option_value = replace(option_value, $old_url, $new_url) WHERE option_name = 'home' OR option_name = 'siteurl'";
  21. $sql_guid = "UPDATE wp_posts SET guid = replace(guid, $old_url, $new_url)";
  22. $sql_content = "UPDATE wp_posts SET post_content = replace(post_content, $old_url, $new_url)";
  23. $sql_postmeta = "UPDATE wp_postmeta SET meta_value = replace(meta_value, $old_url, $new_url)";
  24.  
  25. $conn->query($sql_options);
  26. $conn->query($sql_guid);
  27. $conn->query($sql_content);
  28. $conn->query($sql_postmeta);
  29.  
  30. $conn->close();
  31.  
  32. header("Location: $new_url");
  33. die();
  34.  
  35. } else {
  36. echo "New URL or OLD url is EMPTY";
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement