Problem with links in UpFront when taking a site live - still pointing back to production

Hi Everyone,
I have created a site in UpFront on a development server. Today I cloned it and made it live. It works really well - but one issue has me stumped and a little frustrated.
The Menu items all switched URL's when it was moved, but the page content did not. They are all referring to the old site - even though I used the 'page' option to link them in the first place.
I have used 2 different search and replace plugins to change the URL's to no avail.
Has anyone come across this issue? If so, what was your fix? I'm hoping there is an easy one as there are 85 pages on this site and they all have links that need to be updated.

The site in question is:
Production: http://staffalacarte.com/campussupply/
Live: http://campussupplyco.com
On the home page (and any page really) you can see the menu on the left goes to the right place on the live site, but on the body of the page you will see it goes to the production site. It also appears that the images are still linked to the production site as well, so those links need to be updated and there are a lot.
Thanks for your thoughts and experiences with this!

  • Predrag Dubajic

    Hi Tammie,

    Hope you're doing well.

    Since this question is related to one of our products I'll move it to our support forum, Members forum is more of a general discussion section and doesn't guarantee staff response.

    Can you try doing a DB query directly instead of using plugins and see if that does the trick for you?
    You can use below query just replace OLD_URL and NEW_URL with correct values:

    UPDATE wp_options SET option_value = replace(option_value, 'OLD_URL', 'NEW_URL') WHERE option_name = 'home' OR option_name = 'siteurl';
    
    UPDATE wp_posts SET guid = replace(guid, 'OLD_URL','NEW_URL');
    
    UPDATE wp_posts SET post_content = replace(post_content, 'OLD_URL', 'NEW_URL');
    
    UPDATE wp_postmeta SET meta_value = replace(meta_value,'OLD_URL','NEW_URL');

    Please make sure to have a full backup of your database before making any changes.

    Best regards,
    Predrag

  • Predrag Dubajic

    Hi Tammie,

    I had a talk with the devs about this and they were actually working on a script to help with migration and they just finished it up.
    Please make a backup of your site and follow the steps from start of the code and that should do the trick:

    // ---- START OF DOMAIN SWAPPING ----
    
    // Insert this script to the end of functions.php of active Upfront child theme
    // Replace olddomain.com with original domain
    // And replace newdomain.com with current domain.
    // Refresh any page on site and it should do the swapping.
    // After that remove the script from functions.php
    
    	// Setup
    	$old = 'olddomain.com';
    	$new = 'newdomain.com';
    
    	// Make it happen
    	$needle = sprintf('#%s#', $old);
    
    	global $wpdb;
    	// posts revisions
    	$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE '%upfront%'", OBJECT );
    	foreach($results as $post) {
    		$content = json_encode(unserialize(base64_decode($post->post_content)));
    
    		if (false !== strpos($content, $old)) {
    			$content = preg_replace($needle, $new, $content);
    			wp_update_post(array(
    				'ID' => $post->ID,
    				'post_content' => base64_encode(serialize(json_decode($content, true)))
    			));
    		}
    	}
    
    	// options
    	$prefix = Upfront_ChildTheme::get_instance()->get_prefix();
    	$theme_slug = sprintf('%s-', $prefix);
    
    	$options = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_name LIKE '%{$prefix}%'", OBJECT );
    	foreach($options as $option) {
    		if (
    			0 === strpos($option->option_name, $theme_slug) &&
    			false === strpos($option->option_name, 'post_image_variants')
    		) {
    			$value = $option->option_value;
    			if (false !== strpos($value, $old)) {
    				$value = preg_replace($needle, $new, $value);
    				update_option($option->option_name, $value);
    			}
    		}
    	}
    // ---- END OF DOMAIN SWAPPING ----

    Let us know how it goes.

    Best regards,
    Predrag

  • Tammie

    Hi Predrag,
    Thank you for this information. However, when I put it at the very end of the functions.php file, save it, and refresh the pages on the site - it does nothing.

    I have made sure to turn off caching as well.

    I have moved it just above the last line of code in the functions.php file which is:
    Campus_supply_co::serve();
    However when I attempt to save it there, this is the error message I receive:

    Your PHP code changes were rolled back due to an error on line 95 of file wp-content/themes/campus-supply-co/functions.php. Please fix and try saving again.

    Call to a member function get_prefix() on null

    Unfortunately, I still have the same issue.

    Thanks!

  • Predrag Dubajic

    Hi Tammie,

    Could you provide us with FTP or cPanel access so we can try applying the script and check what's going on?
    NOTE: Please make sure that you have a backup of your site before sending the details in.

    You can send us your details using our contact form https://premium.wpmudev.org/contact/#i-have-a-different-question and the template below:

    Subject: "Attn: Predrag Dubajic"
    - Site login url
    - WordPress admin username
    - WordPress admin password
    - FTP credentials (host/username/password)
    - cPanel credentials (host/username/password)
    - Link back to this thread for reference
    - Any other relevant urls/info

    Best regards,
    Predrag

  • Predrag Dubajic

    Hi Tammie,

    I did receive your email and answered to it yesterday.

    Our developers are still looking into this, it seems that the script I provided you is having issues with the subfolder domain structure, and when they sorted that out the test on our end was good but for some strange reason it still didn't work on your installation.
    They are still on it and trying to find out what happened, and hopefully we will have some good news soon.

    Best regards,
    Predrag

  • Predrag Dubajic

    Hi Tammie,

    Our developers have updated the script on your site earlier today and your links should be updated now.

    Please check it out and let us know if they are working properly now.

    I will update this response with new script that was used on your site, just in case someone with similar issue ends up on this ticket :slight_smile:

    // ---- START OF DOMAIN SWAPPING ----
    
    // Insert this script to the end of functions.php of active
    // Upfront child theme. Replace olddomain.com with original domain
    // And replace newdomain.com with current domain.
    // Refresh any page on site and it should do the swapping.
    // After that remove the script from functions.php
    
    	// Setup
    	$old = 'olddomain.com';
    	$new = 'newdomain.com';
    
    	// Remove protocol
    	$old = preg_replace('#^https?://#', '//', $old);
    	$new = preg_replace('#^https?://#', '//', $new);
    
    	// Make it happen
    	$needle = sprintf('#%s#', addcslashes($old, '\\'));
    
    	global $wpdb;
    	// Posts Revisions
    	$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type LIKE '%upfront%'", OBJECT );
    	foreach($results as $post) {
    		$content = json_encode(unserialize(base64_decode($post->post_content)));
    
    		if (false !== strpos($content, $old)) {
    			$content = preg_replace($needle, $new, $content);
    			wp_update_post(array(
    				'ID' => $post->ID,
    				'post_content' => base64_encode(serialize(json_decode($content, true)))
    			));
    		}
    	}
    
    	// Options
    	$prefix = Upfront_ChildTheme::get_instance()->get_prefix();
    	$theme_slug = sprintf('%s-', $prefix);
    
    	$options = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_name LIKE '%{$prefix}%'", OBJECT );
    	foreach($options as $option) {
    		if (
    			0 === strpos($option->option_name, $theme_slug) &&
    			false === strpos($option->option_name, 'post_image_variants')
    		) {
    
    			$value = $option->option_value;
    			if (false !== strpos($value, $old)) {
    				$value = preg_replace($needle, $new, $value);
    				update_option($option->option_name, $value);
    			}
    		}
    	}
    // ---- END OF DOMAIN SWAPPING ----

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.