I am using a loop to display custom field values in a navigation area. Example: I have 100 posts on the page. Each post has a Brand associated with it (Fender, Gibson, etc.) maybe about 15 brands overall. The navigation loop will output the Brand custom field value for the posts. I want it to only show a brand once, so that instead of outputting 100 Brand values, the loop only outputs 15 unique values, with no duplicates. Everything google shows me about preventing duplicates has to do with wanting a second loop not to duplicate anything from the first loop. This is not my issue - I simply want to prevent duplicate output in a single loop. Any advice? Thank you.
<?php
$args=array('posts_per_page' => -1, 'post_status' => 'publish', 'orderby'=> 'title', 'order' => 'ASC', 'cat' => get_query_var( 'cat' ) );
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<?php
while ($my_query->have_posts()) : $my_query->the_post();
?>
<h3 style="padding-left:10px;"><a href="<? the_permalink() ?>" title="<? the_title() ?>"><?php
$key_1_value = get_post_meta( get_the_ID(), 'brand_value', true );
// check if the custom field has a value
if( ! empty( $key_1_value ) ) {
echo $key_1_value;
}
?></a></h3>
<?php endwhile; ?>
<?php }
wp_reset_query();
?>