0

I am combining all of my css files into one file via PHP using

header('Content-type: text/css');

Within that processed PHP file, I want to get a field from an options page within Advanced Custom Fields.

the_field('field_name', 'option');

Even though I can successfully call the field in the section in 'header.php', I can't get it within the PHP file processing my css. Is there a way to do this?

1 Answer 1

1

I'm not sure what exactly your setup is or where this file is but ACF saves its values as post meta. So you could simply use WP's get_post_meta() if ACF isn't available.

For Example:

get_post_meta( get_the_ID(), 'field_name', true );

You can also have a look at this article, it talks about using get_post_meta vs ACF functions.

4
  • Thank you. Do you have an example of how to use get_post_meta() with ACF data?
    – jons
    Commented Sep 3, 2019 at 19:24
  • I updated the answer Commented Sep 3, 2019 at 19:33
  • Thank you so much @riddlemethis. I appreciate your time very much!
    – jons
    Commented Sep 3, 2019 at 23:06
  • It wasn't working on first try. I don't have a post_id because it is coming from an Options page in ACF Pro. It is my understanding that the string 'option' or 'options' is used in that case. But that was not working either.
    – jons
    Commented Sep 4, 2019 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.