I am using ACF to create blocks for Gutenberg.
I have the folder structure
/blocks/block_name/block-file.php
/blocks/wf-block-start.php
/blocks/wf-block-end.php
in block-file.php, I have it coded as so:
get_template_part('blocks/wf-block-start');
// ACF Repeater fields here
get_template_part('blocks/wf-block-end');
This works fine and returns the repeater rows within block-file.php (removed to make it easier to read).
In my wf-block-start.php file (included via get_template_part), it is coded as so:
$the_id = get_the_ID();
$wf_settings_width = get_field('wf_settings_container_size', $the_id);
echo $wf_settings_width;
echo get_field('wf_settings_container_size', $the_id);
echo get_field('wf_settings_container_size');
None of the values are returning from get_field on the front end from files included using get_template_part.
When doing the following within wf-block-start.php, it returns data just fine:
global $post;
print_r($post); // Works fine
echo $post->ID; // Works fine
echo get_the_ID(); // Works fine
echo get_field('test_field'); // Doesn't work
echo get_field('test_field', $post->ID); // Doesn't work
echo get_field('test_field', get_the_ID()); // Doesn't work
// Test field in Options
print_r(get_field('test_field','options')); // Doesn't work
What’s strange is that it works perfectly fine when editing via block editor – the fields return correctly.
Page.php (excluding header/footer):
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
Any ideas?