Support

Account

Home Forums Add-ons Repeater Field List posts grouped by sub-field of repeater Reply To: List posts grouped by sub-field of repeater

  • for now I have this:

    <?php
    $args = array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘eventos’,
    ‘status’ => ‘programa’,
    ‘orderby’ => array(
    ‘title’ => ‘ASC’)
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <hr>
    <?php the_field(‘evento-viagem’); ?> / <?php the_field(‘evento-audiencia’); ?><br>
    “><?php the_title(); ?><br>
    <?php if( get_field(‘evento-subtitulo’) ): ?>
    <?php the_field(‘evento-subtitulo’); ?><br>
    <?php endif; ?>
    <?php the_field(‘evento-caminho’); ?> <?php the_field(‘evento-ano’); ?><br>

    <?php if( have_rows(‘evento-paragens’) ): ?>

      <?php while( have_rows(‘evento-paragens’) ): the_row(); ?>

    • <?php the_sub_field(‘evento-data’); ?> — <?php the_sub_field(‘evento-hora’); ?>

      <?php
      $posts = get_sub_field(‘evento-local’);
      if( $posts ): ?>
      <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
      <?php echo get_the_title( $p->ID ); ?> <?php the_field(‘local-cidade’, $p->ID); ?>
      <?php endforeach; ?>
      <?php endif; ?>

    • <?php endwhile; ?>

    <?php endif; ?>

    <?php endwhile; ?>

    wich Outputs something like this:

    DAY 1 — HOUR — EVENT A — CITY
    DAY 1 — HOUR — EVENT A — CITY
    DAY 2 — HOUR — EVENT A — CITY
    DAY 2 — HOUR — EVENT A — CITY

    DAY 1 — HOUR — EVENT B — CITY
    DAY 1 — HOUR — EVENT B — CITY
    DAY 2 — HOUR — EVENT B — CITY
    DAY 2 — HOUR — EVENT B — CITY