Home › Forums › General Issues › Set relationship field value on new post › Reply To: Set relationship field value on new post
I got it working now! I think the problem was that I wasn’t casting the id to an int. I changed it and added a check to make sure we are looking at a new post:
public static function setAddress($value, $post_id, $field): mixed
{
$post = get_post($post_id);
// Check we are on the new screen
if ($post->post_status === 'auto-draft') {
$address_id = $_GET['address_id'] ?? false;
if ($address_id) {
$value = [(int) $address_id];
}
}
return $value;
}
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.