Hi there,
I have a widget that display several fields from a specific post (within a Custom Post Type).
The problem is that if I loop through a Repeater fields, then it returns an INT which represents the count of the rows, but not the rows itself.
Tried event with get_post or query_posts: the first one didn’t work, query_posts breaks the layout (maybe because i’m using Site Origin Page Builder to build pages).
// $carousel_id comes from the widget's UI and it's a post ID
$args = array(
'post_type' => 'carosello_custom',
'post__in' => array($carousel_id),
);
$carousel_query = new WP_Query($args);
echo "<div class='latest-post-carousel'>";
if($title) {
echo "<h2 class='carousel-heading'>".$title."</h2>";
}
echo "<div class='generic-carousel custom-carousel'>";
while ( $carousel_query->have_posts() ) {
$carousel_query->the_post();
if( have_rows('elementi') ):
// loop through the rows of data
while ( have_rows('elementi') ) : the_row(); ?>
<div class="carousel-item">
<a class="permalink" href="<?php the_sub_field('link_el'); ?>" title="<?php the_sub_field('titolo_el'); ?>">
<?php
$cover = get_sub_field('immagine_el');
$the_title_attr = get_sub_field('titolo_el');;
if($cover) {
$thumb = $cover['sizes']['thumbnail'];
echo "<img src='$thumb' alt='$the_title_attr'>";
}
?>
<h3 class="entry-title"><?php the_sub_field('titolo_el'); ?></h3>
<span class="carousel-button">SCOPRI</span>
</a>
</div>
<?php
endwhile;
else :
// tried some debug here
the_field('elementi'); // Repeater field: returns row count
the_field('test_r'); // Repeater field: returns row count
the_field('testo'); // Text field: returns content
endif;
}
echo '</div><!-- .posts-carousel -->';
echo '</div><!-- .latest-post-carousel -->';
wp_reset_postdata();
The topic ‘ACF Repeater returns Sub-row count instead of array’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.