Support

Account

Home Forums ACF PRO Detect if a field is being loaded for editing or for being displayed Reply To: Detect if a field is being loaded for editing or for being displayed

  • Hi John, as always, you are the fastest! 🙂

    is_admin() is not enough for my use case, not even in combination with !wp_doing_ajax(). I often also use get_field() in the admin area, for example to display ACF field data in manage_post_posts_custom_column or the like.

    I came up with an admittedly pretty hacky solution:

    
    // inside the acf/load_value callback:
    /**
     * Don't touch the value if it was requested by <code>acf_render_fields</code>
     */
    $backtrace = wp_debug_backtrace_summary(null, 0, false);
    if( array_search('acf_render_fields', $backtrace) !== false ) return $value; 
    

    This checks if the function was invoced by acf_render_fields(), which is only used when an ACF form is being rendered (also when using acf_form() in the frontend).

    Anyways, thanks for helping me think!! 🙂