Home Forums Gutenberg ACF context for secondary loops in Gutenberg blocks


ACF context for secondary loops in Gutenberg blocks

  • I have a Gutenberg block that includes a secondary loop, and in that loop I need to get ACF values. I can do this by specifying a post ID as the second parameter of the_field(). However, this won’t work in my situation. I need to get ACF values without specifying that second parameter. Is there a way to do this in a Gutenberg block? Can I update the ACF context somehow?

    Here’s an example:

    $args = array(
      'post_type' => 'cpt_slug',
    	'p' => $cpt_id,
    $the_query = new WP_Query( $args );
    if ($the_query->have_posts()) {
      while ($the_query->have_posts()) {
        the_field('acf_slug'); // This works in a page template, but not in a Gutenberg block template.
        the_field('acf_slug', get_the_ID()); // This does work in a Gutenberg block template, but I can't use this for reasons.

    If needed I can explain why I can’t use the second parameter.

Viewing 1 post (of 1 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.