Support

Account

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