Home › Forums › ACF PRO › How to add custom class to admin_body_class based on ACF field data? › Reply To: How to add custom class to admin_body_class based on ACF field data?
You are attempting to access to value of the field outside of “The Loop”. This means that ACF will not know what post to get the value from and you must supply that.
$queried_object = get_queried_object();
if (is_a($queried_object, 'WP_Post')) {
$value = get_field('field_name', $queried_object->ID);
}
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.