Support

Account

Home Forums General Issues get_field() is empty in WP_Query inside Gutenberg block

Solving

get_field() is empty in WP_Query inside Gutenberg block

  • Hi,

    I have a WordPress template based on Sage which is using the new ACF blocks feature and Blade templates. Everything is working just fine.

    I have a Gutenberg block that pulls some posts with WP_Query then loops through them this way:

    $projects = new WP_Query(…);
    
    while ($projects->have_posts()): $projects->the_post();
        the_title(); // works
        the_ID() // works
        the_field('location') // does not work
        the_field('location', get_the_ID()); // works
    endwhile;
    
    wp_reset_query();

    Do you have any idea why the_field() fails without passing an ID even though the_post seems to be set up properly (because the_ID() works correctly)?

    Thanks in advance,
    Mary

  • I can’t explain, but I am using Sage + ACF Blocks and this helped, thanks @marijan !

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

The topic ‘get_field() is empty in WP_Query inside Gutenberg block’ is closed to new replies.