简体   繁体   English

为什么我的ACF自定义字段总是返回false或数组?

[英]Why does my ACF custom field return always false or array?

I'm using ACF for WordPress and I've made an update to it. 我将ACF用于WordPress,并对其进行了更新。 After that it seemed to work ok until I'm trying to display the value of a field. 之后,在我尝试显示字段的值之前,它似乎工作正常。 In admin everything works ok. 在管理一切正常。 The custom field value is saved. 自定义字段值已保存。 But when I do a var_dump I get bool false: 但是当我执行var_dump时,我会得到布尔值false:

<?php 
  $my_field = get_field('my_field');
  var_dump($my_field);
?>

And when I replace the get_field value with the custom field key I get array{}: 当我用自定义字段键替换get_field值时,我得到了array {}:

<?php 
  $my_field = get_field('field_5245445r7a7po');
?>

I've tried creating other custom field. 我尝试创建其他自定义字段。 The field is created and saved. 该字段已创建并保存。 Same result. 结果相同。 Nothing displaying. 什么都没显示。

I've also downgraded the plugin to the previous version. 我还将该插件降级为以前的版本。 Nothing seems to work. 似乎没有任何作用。

What will be a possible solution to resolve this? 有什么可能的解决方案来解决这个问题?

Thank you. 谢谢。

Hmm. 嗯。 Looks like I solved this on my own. 好像我自己解决了这个问题。 I'll post the answer, maybe this will help someone else. 我将发布答案,也许这会帮助其他人。

So, in my case, I had a custom query with a while loop for posts before the get_field action. 因此,以我为例,我在get_field操作之前有一个带有while循环的帖子自定义查询。 What I had to do to resolve my problem? 我必须做什么来解决我的问题? Used the next code after the loop, before the get_field action: 在循环之后,在get_field操作之前使用了下一个代码:

<?php wp_reset_query(); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM