Support

Account

Home Forums Gutenberg WP Query inside acf_block, the_field not working.

Unread

WP Query inside acf_block, the_field not working.

  • Hi, I have the following code

    <?php
    $post_object = get_field( 'select_test' ); // Returns ID
    $args = array(
        'post_type' => 'test',
        'post__in' => array($post_object)
    );
    $query = new WP_Query( $args );
    if ($query->have_posts()) :
        while($query->have_posts()) : $query->the_post();?>
            <div class="c-block c-test">
                <div class="o-container o-container--gutenberg">
                    <div class="c-test__questions">
                    <?php the_field('button_text'); ?> // This shows nothing
                    <?php the_title(); ?> // This returns correct title
                    </div>
                    <div class="c-test__results"></div>
                </div>
            </div>        
        <?php 
        endwhile;
        wp_reset_query();
    endif;

    It works fine if I do
    <?php the_field('button_text',get_the_ID()); ?>

    But I would like to build on this without passing the ID all the time, because I guess that’s how it supposed to be inside this loop?

    I have tried to reset query before running this query to no avail.

    It works as intended when used in a regular template i.e. single.php

Viewing 1 post (of 1 total)

The topic ‘WP Query inside acf_block, the_field not working.’ is closed to new replies.