WordPress试图获得ACF字段的值总是返回null

发布于 2025-02-03 06:25:57 字数 575 浏览 5 评论 0原文

我正在尝试通过ACF中的一个现场群体循环,并在该组中获得某些字段的价值。

这对于ID来说非常有效,并且$ fields = acf_get_fields(1996)效果很好,但是为什么它总是返回我的变量$ thename的null?

我已经把头缠住了2个小时,我只是不知道为什么它不访问给定的字段。

我忘记了什么还是逻辑扭曲?

感谢任何帮助。

$fields = acf_get_fields(1996);
$thename = get_field('field_5e171593783a1', 1996);
$json = [];

foreach ($fields as $name => $value) {

    array_push($json, 'ID: ' . $value['ID'], $value[$thename]);

}

解决的

发现我使用了错误的帖子ID-而不是使用我要访问的帖子的帖子ID,而是错误地使用了现场组本身的帖子ID,这确实没有因此,任何值最终都返回null。

I am trying to loop through a field group in ACF and get the value of certain fields inside that group.

This is working pretty good for the ID and $fields = acf_get_fields(1996) works perfectly aswell but why does it always return NULL for my variable $thename?

I have been wrapping my head around this for like 2 hours now and I just can't figure out why it doesn't access the given field.

Did I forget something or is my logic twisted?

I appreciate any help.

$fields = acf_get_fields(1996);
$thename = get_field('field_5e171593783a1', 1996);
$json = [];

foreach ($fields as $name => $value) {

    array_push($json, 'ID: ' . $value['ID'], $value[$thename]);

}

SOLVED

Found out that I used the wrong Post ID - instead of using the Post ID of the post I was trying to access, I wrongly used the Post ID of the field Group itself, which indeed did not have any values so ended up returning NULL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文