Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'wp-config.php';
- $servername = DB_HOST;
- $username = DB_USER;
- $password = DB_PASSWORD;
- $dbname = DB_NAME;
- $old_url = "";
- $new_url = "";
- if ( !empty($old_url) && !empty($new_url) ) {
- $conn = new mysqli( $servername, $username, $password, $dbname );
- if ( $conn->connect_error ) {
- die( "Connection failed: " . $conn->connect_error );
- }
- $sql_options = "UPDATE wp_options SET option_value = replace(option_value, $old_url, $new_url) WHERE option_name = 'home' OR option_name = 'siteurl'";
- $sql_guid = "UPDATE wp_posts SET guid = replace(guid, $old_url, $new_url)";
- $sql_content = "UPDATE wp_posts SET post_content = replace(post_content, $old_url, $new_url)";
- $sql_postmeta = "UPDATE wp_postmeta SET meta_value = replace(meta_value, $old_url, $new_url)";
- $conn->query($sql_options);
- $conn->query($sql_guid);
- $conn->query($sql_content);
- $conn->query($sql_postmeta);
- $conn->close();
- header("Location: $new_url");
- die();
- } else {
- echo "New URL or OLD url is EMPTY";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement