Support

Account

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
      
    ?>