Home › Forums › ACF PRO › Sort posts by ACF custom field AND display sorting meta_value › Reply To: Sort posts by ACF custom field AND display sorting meta_value
I’m not quite sure how to work this into your code, I’m not sure where you want to output the unique value or how to work it into the list structure you have going.
If the posts are sorted by regione
then you can to something like this:
// the last region displayed, starts empty
$last_regione = '';
while ($my_query->have_posts()) {
$my_query->the_post();
$this_regione = get_field('regione');
// test to see if we've changed regions
// this will always be true for the first post
if ($this_regione != $last_regione) {
// code here to display new region heading
}
// set last region to this region for the next loop
$last_regione = $this_regione;
// remainder of your code to display post continues here
} // end while have posts
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.