Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange.
Closed 6 years ago .
I have created a custom true/false field with the default value of true. I’ve set different posts to different values. However, get_field() always returns false:
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>
<?php global var_dump(get_field('display_featured_image'));?>
<?php endwhile; endif ?>
The displayed output is: (bool)false
I’ve checked and double checked the field name. Why would it return false if the value is set to true?
You need to pass in the ID of the post you’re trying to get the field from: Eg
get_field('display_featured_image', $post_id).
In a loop you could do
get_field('display_featured_image', get_the_id());
ACF Stores field data in wp’s meta_fields, so you could even use WP’s built in meta handler to pull the data yourself Eg:
get_post_meta( $post_id, 'acf_field_name', true); // Use true for almost every case, as WP will return an array otherwise.