Skip to content

Instantly share code, notes, and snippets.

@davekuhar
Created July 26, 2025 17:09
Show Gist options
  • Save davekuhar/70086cdfb22b063e4abeee6cef1f715d to your computer and use it in GitHub Desktop.
Save davekuhar/70086cdfb22b063e4abeee6cef1f715d to your computer and use it in GitHub Desktop.
Elementor does some dumb things with site URLs,this script cleans that up
<?php
// Load WordPress environment
require_once( dirname(__FILE__) . '/wp-load.php' );
// Define old and new URLs
$old_url = 'https://blxtraining.com';
$new_url = 'https://biologix-wcupdate.sitedistrict.com';
// Query all postmeta with Elementor data
global $wpdb;
$results = $wpdb->get_results("
SELECT meta_id, meta_value
FROM {$wpdb->postmeta}
WHERE meta_key = '_elementor_data'
AND meta_value LIKE '%$old_url%'
");
foreach ( $results as $row ) {
$meta_id = $row->meta_id;
$meta_value = $row->meta_value;
// Decode the serialized JSON
$data = maybe_unserialize( $meta_value );
// Replace the old URL with the new one
$updated_data = json_decode( str_replace( $old_url, $new_url, json_encode( $data ) ), true );
// Reserialize and update the database
$wpdb->update(
$wpdb->postmeta,
[ 'meta_value' => maybe_serialize( $updated_data ) ],
[ 'meta_id' => $meta_id ],
[ '%s' ],
[ '%d' ]
);
echo "Updated meta_id: $meta_id\n";
}
echo "URL replacement complete.\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment