Support

Account

Home Forums Gutenberg Cannot access ACF Field Value for CPT post when called via Gutenberg Block

Solving

Cannot access ACF Field Value for CPT post when called via Gutenberg Block

  • I’m having an interesting bug:

    I have a CPT called Locations, in it i have a list of locations and ACF color picker fields for those locations called “color” (each location has a color assigned to it.)

    Simple enough, works throughout, however now I’m building that same element out into a Gutenberg Block that, via a Post Object field, calls these locations, and displays them. That also works just fine, i’m able to get the names, permalinks, all relevant post data – however when in the the loop for these locations, any call for the_field(); that when used outside of the gutenberg block are called fine, in this the block return nothing.

    I’m curious if there is something more that has to be done to access ACF fields from posts called from post object fields inside of Gutenberg blocks?

  • I was able to solve my own question – not entirely sure why, as i’m in the loop but by adding the explicit $post-ID to the_field call. IE:

    <?php the_field('location_color', $post->ID); ?>

    I was able to access the fields. If anyone has the explanation for why that is, i’d be curious to hear it. But there’s the solution regardless.

  • It looks like you may have found the solution for an issue I was having earlier today @tanmccuin , Thank You!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.