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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.