Home › Forums › General Issues › Query by repeater field, order and categorise › Reply To: Query by repeater field, order and categorise
Hi @elliot
Many thanks for your help.
This hasn’t outputted as expected. Looks like there’s both last name and last name for each artist (instead of first/last) and then it’s still not grouping all the Bs, all the Cs etc together.
I managed to fix the first name/last name stuff, but it’s still not grouping.
This is my full code below. Hope you can help, and many thanks for your help so far.
<?php query_posts ( array (
'post_type' => 'programme',
'category_name' => 'archive',
//'meta_key' => 'last_name',
//'orderby' => 'meta_value',
//'posts_per_page' => -1,
'order' => 'DESC' ) ); ?>
<div class="container_12">
<div class="prefix_1 grid_10 suffix_1">
<?php while ( have_posts() ) : the_post(); ?>
<?php
$groups = array();
if ( have_rows('artists') ) {
while ( have_rows('artists') ) {
the_row();
// vars
$first_name = get_sub_field('first_name');
$last_name = get_sub_field('last_name');
$first_letter = substr($last_name, 0, 1);
// add $first_letter holder to groups
if( !isset($groups[ $first_letter ]) ) {
$groups[ $first_letter ] = array();
}
// append artist to group
$groups[ $first_letter ][] = $first_name . ' ' . $last_name;
}
}
// ouput
if( !empty($groups) ): ?>
<?php foreach( $groups as $letter => $artists ) : ?>
<h3><?php echo $letter; ?></h3>
<?php foreach( $artists as $artist ): ?>
<p><?php echo $artist; ?></p>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
</div>
<div class="clear"></div>
<?php wp_reset_postdata(); ?>
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.