简体   繁体   中英

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. 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:

<?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{}:

<?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. What I had to do to resolve my problem? Used the next code after the loop, before the get_field action:

<?php wp_reset_query(); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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