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?