ACF Repeater content within a query loop - array map?

Unless I’m misunderstanding, IMO a nested array_map would be the way to go. IIRC ACF repeater fields just return an array, so it should be as simple as this:

public function propertyLoop() { 
  return array_map(function ($post) {
      return [
          'bathrooms'     =>      get_field('property_bathrooms', $post),
          'sleeps'        =>      get_field('property_sleeps', $post),
          'bedrooms'      =>      get_field('property_bedrooms', $post),
          'title'         =>      apply_filters('the_title', $post->post_title),
          'introduction'  =>      get_field('property_introduction'),
          'link'          =>      get_permalink($post->ID),
          'gallery'       =>      array_map(function($image) {
             return wp_get_attachment_image($image); // Or however you want to process this
          }, get_field('property_gallery', $post)),
      ];
  }, get_posts([ 'post_type' => 'property', 'posts_per_page'=> -1, ]));
}
1 Like