Home Forums ACF PRO Can't get_field in ACF Block


Can't get_field in ACF Block

  • I’m stumped by what should be a dead-simple operation I’ve done dozens of times before.

    I have a Block built with ACF Pro. It has a single Repeater field with one subfield that are Post Objects (returning Posts).

    The posts selected in the Repeater have an ACF Field Group with several fields, including two Images returning IDs.

    My plan was to loop through the posts and pull the data out with get_field(‘field_name’, post_id). But neither get_field or get_sub_field are returning any data, even though I can verify the ID on each post.

    $stories = 0;
    // gets the count of the number of stories
    $stories_repeater = get_field(‘stories’);
    $stories = count($stories_repeater);
    $pagers = “”;
    // loop through stories
    if (have_rows(‘stories’)) {
    while (have_rows(‘stories’)) : the_row();
    // get the post reference for the story
    $story = get_sub_field(‘story’);
    // get the image referenced by the story’s ‘story_pager_image’ field
    $story_pager = wp_get_attachment_image(get_field(‘story_pager_image’, $story->ID));
    $pagers .= ‘<div class=”story-pager-‘.(get_row_index()).'”>’.$story_pager.'</div>’;
    echo $pagers;

    This should print each image enclosed in a div, but no value is returned by the get_field for story_pager_image. It seems like a no-brainer.

  • Never mind. As I suspected, user error.

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

You must be logged in to reply to this topic.