Home › Forums › Add-ons › Repeater Field › List posts grouped by sub-field of repeater
Hi,
I wonder id anyone can help me on this issue:
I have a custom post type (events) organised under 2 categories (past and current), each event has several occurrences managed with a repeater field (evento-paragens) with several sub-fields: event-date, event-hour, event-venue (this last one is a relational field).
What I pretend is to list the events by occurrence and grouped by date:
DAY 1
HOUR — EVENT A — CITY
HOUR — EVENT B — CITY
HOUR — EVENT A — CITY
HOUR — EVENT B — CITY
DAY 2
HOUR — EVENT A — CITY
HOUR — EVENT B — CITY
HOUR — EVENT A — CITY
HOUR — EVENT B — CITY
Until now what I could achieve was a list of all occurrences grouped by event:
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
I’ve searched for a lot of forums but it seems that none of the examples suites my case. Maybe because the I need to group by a sub-field.
Any ideas?
M
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
$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
does this help: https://support.advancedcustomfields.com/forums/topic/order-by-subfield-values/
seems like you can do subnested orderbys now: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
(i didn’t know about this until now – very exciting!)
Phil
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.