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!! 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.