Support

Account

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

  • In case you stumble upon the aforementioned solution at https://support.advancedcustomfields.com/forums/topic/preview-solution/page/3/#post-136816 and need to fix your options fields this slightly modified snippet worked for me:

    function fix_post_id_on_preview($null, $post_id) {
        if (is_preview() && $post_id !== 'options') {
            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 );

    Obviously works only if you’re using ‘options‘ in your get_field calls, not the singular ‘option’.