Support

Account

Home Forums General Issues Dispalay ACF values in alphabetical order

Solved

Dispalay ACF values in alphabetical order

  • I have a loop displaing all values of a specific field in a custom template page. This avoid to repeat same values twice or more and works fine.
    My goal is to display values in alphabetical order. How I can do it?
    Thanks in advance.

    
    <div class="prod-company-items">
    
    <?php
            $args = array(
              'post_type' => 'credits',
              'posts_per_page' => -1,
            );
    
            // La Query
            $kc_query_companies = new WP_Query( $args );
            $kc_productions = array();
    
            // the Loop
            while ( $kc_query_companies->have_posts() ) :
              $kc_query_companies->the_post();
              $kc_productions[] = get_field('production_company'); ?>
            <?php endwhile;
    
            $kc_productions = array_unique( $kc_productions );
    
            foreach ( $kc_productions as $kc_production ) { ?>
              <p class="prod-company-item">
                <?php echo $kc_production; ?>
              </p>
            <?php }
    
            // Reset Query & Post Data
            wp_reset_query();
            wp_reset_postdata(); ?>
          </div>
    
  • +1 on this. Exactly what I am looking for. Display Custom Post Types in alphabetical order and, to go even further, a filter with the letters of the alphabet on top of the posts giving the ability to select each letter and filter posts accordingly.

    Maybe too complicated?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.