Home > Software design >  ACF repeaater Not working even after coding the fields right
ACF repeaater Not working even after coding the fields right

Time:10-05

My code

<?php if( have_rows('mir_global_header') ): ?>
<div id="mid-bg1">
    <div id="top-container1">
        <?php while( have_rows('mir_global_header') ): the_row();
                        $count = get_row_index();
                        $header_image = get_sub_field('header_image');
                        $header_image_text = get_sub_field('header_image_text');
                        ?>
                        <img src="<?php echo $header_image; ?>" id="<?php echo $count; ?>" alt="<?php echo $header_image_text; ?>" />
        <?php endwhile; ?>
    </div>
</div>
<?php endif; ?>

enter image description here

enter image description here

I've done everything as mentioned in the documentation. It's not working. Is it because ACF pro is not activated? Is there any other way to do this? Thanks in advance

CodePudding user response:

If you're using ACF options page. You have to specify that in the have_rows. https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/

<?php if( have_rows('mir_global_header', 'option') ): ?>
    <div id="mid-bg1">
        <div id="top-container1">
            <?php while( have_rows('mir_global_header', 'option') ): the_row();
                $count = get_row_index();
                $header_image = get_sub_field('header_image');
                $header_image_text = get_sub_field('header_image_text');
                ?>
                <img src="<?php echo $header_image; ?>" id="<?php echo $count; ?>" alt="<?php echo $header_image_text; ?>" />
            <?php endwhile; ?>
        </div>
    </div>
<?php endif; ?>

CodePudding user response:

Are your fields in an options page or a classic post_type?

Test this for print a result

$mir_global_header = get_field('mir_global_header');
echo '<pre>';
print_r($mir_global_header );
echo '</pre>';die();

PS : ACF Gallery gives the same result ;) https://www.advancedcustomfields.com/resources/gallery/

  • Related