WordPress试图获得ACF字段的值总是返回null
我正在尝试通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论