Skip Navigation

[Resolved] Relative or changing absolute path

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 3 voices.

Last updated by chrisH-10 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1195589

Hello,

My custom type have and image as custom field. I'm developing on localhost so if I use absolute path, then path starting with localhost stays there with image. All the files in media library have their domain changed when I upload it to live server, but not custom field of toolset.

I wanted to use relative paths, but according to other tickets you don't support it.

Could you please help me solve this issue? How to force domain change on custom fields?

Best regards,
Ferdinand

#1195684

Hi, a good site migration tool will update the image URLs in your custom fields during migration of the database (DB). I use Duplicator Pro, but there are other 3rd-party plugins available that will help facilitate text replacement in the DB during migration. Other than that, you have the option to write your own DB migration script, but I don't recommend that unless you're comfortable writing SQL queries to manipulate the DB directly. WordPress's documentation also has some migration information you may find useful: https://codex.wordpress.org/Moving_WordPress

#1351021
#1351063

Here's some code you can throw into your functions.php file to change the URLs output by 'raw' to be site relative.

/* Toolset Views: If the feature image output is "raw" convert the URLs emitted to a site relative path */
add_filter( 'wpv-post-featured-image', 'site_relative_featured_image' );
function site_relative_featured_image( $in ) {
	if (substr($in, 0, 4) === "http") {
		$in_arr = explode("/", $in);
		$in_arr = array_slice($in_arr, 3);
		$out = "/" . implode("/", $in_arr);
		return $out;
	} else {
		return $in;
	}
}