Your Location is: Home > Php

Advanced Custom Fields not populating on page

From: Vienna View: 2734 May Hitchings 

Question

I followed the ACF documentation code example for inserting custom fields onto the page, but haven't had any luck seeing it actually display. I'm new to php so I'd love another set of eyes on this.

I inserted this code:

<div class="date_effective"><!-- date effective -->
    <?php if( get_field('date_effective') ):?>
    <?php echo get_field('date_effective'); ?>
    <?php endif; ?>
</div>

into the content.php file within my theme, which is a child theme of WP Bootstrap Starter.

Best answer

The php code looks correct but I would try making sure a couple things.

  1. 'date_effective' has a value by printing it prior to the if statement - you can also use "the_field('date_effective')" to print to the field to the screen.

  2. Make sure the field isn't blank on your WordPress page. Sometimes if you add information to a field and then change the field type or aspects it will remove the data from the field.