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:
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?
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)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users