Home › Forums › General Issues › Page Link, Archive, Absolute URL
Hello. I’m curious if anyone else has come across this issue and has a solution.
I’ve been using the Page Link field to create some menus on various pages and it’s been working great. I have noticed one issue that if I select an Archive as the page link. The URL is an absolute URL not a relative one.
So when I change environments from local to dev, staging, prod. The URL is locked into the whatever environment the page link was made on. I’ve tried re-saving my permalinks but this didn’t solve my problem.
I only experience this issue with archives, not when selecting pages.
Any help on solving this issue would be appreciated. Right now my only solution is to go back to the website and update manually the URLs for each environment.
I have one site where I have this issue because I have 3 dev/staging/testing sites with different domain names. In my case I created an filter. All of the domain names include “company-name.com” so I am able to only effect links if they contain the this value.
https://www.advancedcustomfields.com/resources/acf-format_value/
add_filter('acf/format_value/type=page_link', 'remove_domain_from_page_link', 20, 3);
function remove_domain_from_page_link($value, $post_id, $field) {
if (stripos($value, 'company-name.com') === false)) {
// value does not contain company-name.com
return $value;
}
$value = preg_replace('#^https?://[^/]*#', '', $value);
return $value;
}
Hi John,
I got the same problem as the owner of the thread.
It is solved by using WP Migrate Lite, in which also replaces serialized strings in the database.
Which then also solves the Page Link component in ACF.
But my problem, is that on local machine, I use port 8080 and 3000 (3000 for webpack/hmr-tooling).
So this is still causing problem locally, but your root-relative snippet is a dream to fix this.
Does this filter hook up when you save your post?
And should it not be much more efficient to use the php to figure out the current HOSTNAME (domain) instead of hardcoding your domain?
This is an old post and I no longer do things like this, meaning I no longer copy data in the database between environments. The original code I posted does not alter saved values, it only alters a value before it is displayed. There is no efficient way to alter the saved values on multiple sites other that a db search and replace tool that deals with serialized data correctly (like the one you mentioned).
The topic ‘Page Link, Archive, Absolute URL’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.