How to: Do not print duplicate entries from query?
-
Hi,
I have this:
<?php // The Query query_posts( 'post_type=fellow' ); // The Loop while ( have_posts() ) : the_post(); ?> <li><a href="#"><?php $fellowship = get_post_meta( get_the_ID(), 'fellowship', true ); // check if the custom field has a value if( ! empty( $fellowship ) ) { echo $fellowship; } ?></a></li> <?php endwhile; ?>
I’d like to set this up so that a fellowship echos only once, no matter how many times it might show up in the query.
I did this same thing a year ago using some different code, but I don’t think this was the best solution, it would be nice to be able to just use the query that’s already there and to do something like:
if the $fellowship has already appeared, skip it.
Here’s the code I used a year ago, in a totally different site:
$args = array( 'posts_per_page' => -1, 'category' => get_query_var( 'cat' ), 'order' => 'ASC', 'orderby' => 'title' ); $brand_list = array(); $posts_array = get_posts($args); foreach( $posts_array as $post ) : setup_postdata($post); $brand = get_post_meta( $post->ID, 'brand', true); if(!in_array($brand,$brand_list)){ array_push($brand_list,$brand); $key_1_value = get_post_meta( get_the_ID(), 'brand', true ); // check if the custom field has a value if( ! empty( $key_1_value ) ) { ?> <li class="menu-item menu-item-type-taxonomy menu-item-object-category"><a href="#" title="<? the_title() ?>" class="<?php $brandnav = get_post_meta(get_the_ID(), 'brand', true); $brandnav_array = explode(' ', $brandnav); $first_word = $brandnav_array[0]; echo $first_word; ?> "> <?php echo $key_1_value; ?> </a></li> <?php } } endforeach; ?>
Any ideas? Thank you.
https://192.185.31.23/~frontpor/wordpress/?page_id=15#
William in Roanoke, Va
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to: Do not print duplicate entries from query?’ is closed to new replies.