Support

Account

Home Forums General Issues Custom Fields on post Preview Reply To: Custom Fields on post Preview

  • The options doesn’t work with the above fixes. I hooked to the hook in the end and simplified abit and it seems this works all the way: previews, blocks, post acf fields _and_ options:

    
    function fix_acf_field_post_id_on_preview($post_id, $original_post_id)
    {
        // Don't do anything to options
        if (is_string($post_id) && str_contains($post_id, 'option')) {
            return $post_id;
        }
        // Don't do anything to blocks
        if (is_string($original_post_id) && str_contains($original_post_id, 'block')) {
            return $post_id;
        }
    
        // This should only affect on post meta fields
        if (is_preview()) {
            return get_the_ID();
        }
    
        return $post_id;
    }
    add_filter('acf/validate_post_id', __NAMESPACE__ . '\fix_acf_field_post_id_on_preview', 10, 2);