Home Forums Front-end Issues Echo ACF Text Field From Inside the Loop on Posts Page


Echo ACF Text Field From Inside the Loop on Posts Page

  • Hey my guys,

    A simple question, just a long one because I wanted to err on the side of providing too much information.

    I’m creating a custom WordPress theme from Underscores with the posts page being the front page. I have an ACF field group set to show on post type milestone (a custom post type registered in functions.php) with only one field, called milestone_subhead (type is text). The only rule for this field group is that it display only on post type milestone.

    So I’m inside the Loop on front_page.php and then I try to use my ACF field with echo '<h3>'.the_field('milestone_subhead').'</h3>';. Nothing, no errors either, though the empty <h3></h3> is rendering in my HTML. So then I wrap that same command an if (get_the_field('milestone_subhead')), with the else being echo '<h3>nothing here</h3>'. It’s obviously evaluating themilestone_subhead field as empty, because “nothing here” renders on the page.

    So obviously, I checked to be sure that the field is actually populated for those posts. It’s there, no question about it. I tried passing an ID to get_the_field(), both explicitly and via get_the_id(). Nothing.

    I know it’s not an issue with the Loop because all the other $post-specific functions (the_title(), the_content(), the_id()) are working perfectly for every post. It’s just the ACF field.


  • Figured it out after hours in the WP codex. I’m sure this little nugget was buried somewhere in the ACF docs, too.
    With custom post types, you have to enable support for custom fields in the register_post_type() function with the help of the supports parameter, which must include the value custom-fields.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Echo ACF Text Field From Inside the Loop on Posts Page’ is closed to new replies.