Support

Account

Home Forums General Issues Preview solution ! Reply To: Preview solution !

  • It seems to me as more of an ACF issue than Gutenberg’s. Apparently if there’s an existing revision/autosave record in the DB of the post being previewed it will just return false when you try to retrieve the field using ACF’s functions. This is a workaround I’m currently testing:

    
    function fix_post_id_on_preview($null, $post_id) {
        if (is_preview()) {
            return get_the_ID();
        }
        else {
            $acf_post_id = isset($post_id->ID) ? $post_id->ID : $post_id;
    
            if (!empty($acf_post_id)) {
                return $acf_post_id;
            }
            else {
                return $null;
            }
        }
    }
    add_filter( 'acf/pre_load_post_id', 'fix_post_id_on_preview', 10, 2 );

    Another workaround would be to just use get_post_meta instead of ACF’s functions