Get first row (image) of ACF repeater field

Asked
Active3 hr before
Viewed126 times

6 Answers

firstimage
90%

i have a page where the images are shown with text next to them (posts). above the posts there’s a small bar with the first image of the last 5 posts. Before i was using a preg replace to get the images and text split up, but now i’m using the repeater field.,I bought the whole package yesterday and i’m very glad with it! Just a minor issue: it seems that i cant get the repeater to only spit the first row!,you can use print_r for view repeater field array and then use first row of array,We've just released ACF Custom Database Tables version 1.1.0 which opens up new possibilities for building high-performance sites using @wp_acf 🎉🥳Here's a little thread covering a few of the new features👇 (1/7)

this is the code:

<div class="postbalk">
   <? query_posts('cat=4'.'&showposts=5'); 	// latest blog story?>
   <?php while (have_posts()) : the_post(); ?>

   (HERE SHOULD BE THE CODE FOR GETTING THE FIRST IMAGE)

   <?php endwhile; ?>

</div>
<div class="blog_div1-blog">
   <?php query_posts ($query_string . '&cat=4'); ?>
   <?php while ( have_posts() ) : the_post() ?>
   <div class="wrap_blog">
      <div class="col_blog_beeld">
         <?php if( have_rows('beelden') ): ?>
         <?php while( have_rows('beelden') ): the_row(); 

		// vars
		$image = get_sub_field('beelden');
		$caption = get_sub_field('caption');

		?>

         <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
         <?php endwhile; ?>
         <?php endif; ?>
load more v
88%

I have 7 posts. all posts have a repeater field with 3 or 4 images. I would like to get the first image from repeater field of all posts. here I get the 3 or 4 images of all posts. you see what I mean ? – mmdwc Jan 15 '14 at 11:52 ,@mmdwc is nearly right. Since the repeater is a nested field then get_field wont retrieve any content as your trying to retrieve a sub field.,I'm using the ACF plugin on my website. I want to display on one page the first row (an image URL) of a repeater field from children page., Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

@mmdwc is nearly right. Since the repeater is a nested field then get_field wont retrieve any content as your trying to retrieve a sub field.

< ? php
$rows = get_sub_field('repeater_field_name'); // get all the rows of the sub field repeater
$first_row = $rows[0]; // get the first row of the repeater
$first_row_image = $first_row['sub_field_name']; // get the sub field value of the nested repeater
?
>
load more v
72%

I have a repeater filed called "images" and inside it I have a sub_filed called "image".,ACF has a function called get_row_index() that you can utilize. Here is how you can possibly use it in your case

ACF has a function called get_row_index() that you can utilize. Here is how you can possibly use it in your case

    <?php
      $active = 'active';
      while ( have_rows('images') ) : the_row();
      $image = get_sub_field('image');
      if(get_row_index() == '1' ):
    ?>
    <img src="<?php echo get_template_directory_uri(); ?>/files/images/<? 
 php the_sub_field('image'); ?>" class="img-fluid is-slider-item" />
    break;
    <?php $active = '';
    endwhile;
    ?>
    <?php endif; ?>
65%

< ? php

// ACF REPEATER - BASIC LOOP

// check if the repeater field has rows of data
if (have_rows('repeater_field_name')):

   // loop through the rows of data
   while (have_rows('repeater_field_name')): the_row();

// display a sub field value
the_sub_field('sub_field_name');

endwhile;

else :

   // no rows found

   endif;

?
>
load more v
75%

I have an ACF repeater field which repeats out images using Timber in wordpress. My code is as...,I see you can simply break out of the loop using the ACF syntax but just can't figure out it its possible to do using Timber. Any ideas would be great. Thanks.,Pretty simple and this returns all the rows I have added to this repeater as expected, but I only want to return the first row, i.e. the first image in the repeater.

I have an ACF repeater field which repeats out images using Timber in wordpress. My code is as...

{
   %
   for item in item.get_field('product_images')
}
} {
   {
      TimberImage(item.product_image).src('thumbnail')
   }
} {
   % endfor %
}
load more v
40%

I have a repeater field with an initial conditional question (radio field) per row to build a gallery of mixed media types.,... the user then updates the post and the DB is updated. Because the first row's image field was conditionally hidden (disabled input), the DB value for this field (repeater_0_image) is never updated.,Note: Even though the first row was selected as a "video" type, the image sub field still contains a value.,I hope to have this fixed in the future. For now, please be sure to strengthen your template code to check the value of the conditional field (not just what values exist).

fieldgroup: banner
field definition: {
   "key": "field_5819e6a65077b",
   "label": "Image small",
   "name": "banner_story_image_small",
   "type": "image",
   "required": 0,
   "conditional_logic": [
      [{
         "field": "field_58d13a0a3e9c4",
         "operator": "==",
         "value": "image"
      }]
   ],
   ...
}
load more v

Other "first-image" queries related to "Get first row (image) of ACF repeater field"