最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get ACF options field in PHP acting as CSS

programmeradmin0浏览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?

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?

Share Improve this question asked Sep 3, 2019 at 18:52 jonsjons 1291 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论