Support

Account

Home Forums General Issues Value doesn't display in post

Solving

Value doesn't display in post

  • Hi all,

    I have created a custom field called tgg, but the code down here doesn’t show any value:

    <?php get_field(‘tgg’); ?> <?php the_field(‘tgg’); ?>

    Could you help me to display the value of this field please?

  • Hi @karnabal

    The issue you had mostly occurred because you were trying to execute the get_field()/the_field() functions outside of The Loop. To fix it, you need to pass the post/page ID as the second parameter to the get_field() function like this:

    get_field(‘custom_field_name’, 99)

    Where “99” is the post/page ID where the custom field is assigned. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_field/.

    I hope this helps 🙂

  • Hey James,

    Thank you. I tried to follow what is written in the recommended page before posting here. 😉

    I can’t specify the post ID because the value is supposed to be attached to the current post. For instance, on the Tomato post, the color field value that is supposed to be displayed is red, when on the salad post, it is green. So how could I display colors dynamically on posts?

  • I get it!

    <?php the_field(‘tgg’); ?>

    I guess the quotes were wrong. 🙂

    But it looks I only can display text type fields. 🙁

  • Hi @karnabal

    Some field types require the usage of the get_field function and a loop to step through array values. Please have a look at the following resource page for more info on the different field types: https://www.advancedcustomfields.com/resources/

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

The topic ‘Value doesn't display in post’ is closed to new replies.