Support

Account

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;
        }