0

I m using ACF, where I have a group.

Inside that group I have a repeater.

All works fine until:

I add a group inside that repeat.

I don't manage to call the field from that group inside the repeater . .. any help will be super !

I'm using the below:

<section class="questions">
    <header class="section-header">
        <h1 class="beta center up-c" data-mobile-font-size="delta"><?php echo $questions['heading'] ?></h1>
    </header>
    <form id="questions-form">


        <div class="questions-slider">
            <?php $i = 1 ?>
            <?php foreach($questions['items'] as $question): ?>
                <div class="slide">
                    <article>
                        <div class="image-container" style="background-image: url(<?php echo $question['image']['url']; ?>)">
                            <img src="<?php echo $question['image']['url']; ?>" alt="<?php echo $question['image']['alt']; ?>" />
                            <h1 class="beta up-c" data-mobile-font-size="delta"><?php echo $question['question'] ?></h1>
                        </div>
                        <div class="flexbox-container padding">

                            <input id="<?php echo 'q' . $i . 'a1' ?>" type="radio" name="<?php echo 'q' . $i ?>" value="1">
                            <label for="<?php echo 'q' . $i . 'a1' ?>">
                            <?php echo $question['answer-one'] ?></label>
                            <input id="<?php echo 'q' . $i . 'a2' ?>" type="radio" name="<?php echo 'q' . $i ?>" value="2">
                            <label for="<?php echo 'q' . $i . 'a2' ?>"><?php echo $question['answer-two'] ?></label>
                            <input id="<?php echo 'q' . $i . 'a3' ?>" type="radio" name="<?php echo 'q' . $i ?>" value="3">
                            <label for="<?php echo 'q' . $i . 'a3' ?>"><?php echo $question['answer-three'] ?></label>


<?php

// vars
$answer = get_field('answer_one');  

 if( $answer ): ?>
    <?php echo $answer['new_answer_one']; ?>
 <?php endif; ?>

                    <div class="question_note">
                                <p class="note_title" data-mobile-font-size="delta"><?php echo $question['note_title'] ?></p>
                                <p class="note_body" data-mobile-font-size="delta"><?php echo $question['note_body'] ?></p>
                                <a class="button button-primary next">Next Question</a>

                            </div>

</div>

                    </article>


                </div>
                <?php $i++ ?>

            <?php endforeach; ?>
        </div>
    </form>
</section>

$questions is the main group

items the repeater

answer that new group...

Thkx so much !

2

You code looks very confusing. Why are you using the 'foreach'?

If you follow the ACF documentation, you just need to use:

<?php
if( have_rows('questions') ):
while( have_rows('questions') ): the_row();
// vars
$repeater-item = get_sub_field('repeater-item');
?>
<div class="content">
<?php the_sub_field('caption'); ?>
</div>

For the group. Source: https://www.advancedcustomfields.com/resources/group/

And you only have to use:

if( have_rows('item') ):
while ( have_rows('item') ) : the_row();
    the_sub_field('item-whatever');
endwhile;
else :
// no rows found
endif;

For the item. Source: https://www.advancedcustomfields.com/resources/repeater/

If you are using a variable called 'questions', where is that variable created and what info is it receiving?

Are you using 'sub_field' or just 'field' in the code?

At least with the info you gave, your code looks completely wrong to me.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.