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 correct that get_field()
will not automatically work because you are on the admin side, however, it is possible to pass the post_id you want the value from as a parameter:
global $post;
get_field('some_field', $post->id);
There is however still an issue with that global post. Especially on post creation this might not work properly and another issue is that you could only see results by saving your changes and then refreshing the page.
My advice is to load some custom javascript in the admin and add/change/remove classes on the admin body using jQuery (or just vanilla).
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.