Home › Forums › ACF PRO › Insert unique ID before first instance of field › Reply To: Insert unique ID before first instance of field
Sorry, it is not 100% clear what you need help with.
You already have all the posts sorted by this “sort” field when you do the query that’s not shown?
You want to “group” the posts in some way by the value of the custom field?
If this is the case then the basic idea would be something like this
<?php
// your query here
if (have_post()) {
$last_sort = '';
while (have_posts()) {
the_post();
$sort = get_field('sort'); // Gives The Sort Letter
if ($sort != $last_sort) {
// the sort leter has changed
?>
<div id="sort-<?php echo $sort; ?>"><?php echo $sort; ?></div>
<?php
// set $last_sort to new $sort
$last_sort = $sort;
} // end if short changed
} // end while have posts
} // end if 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.