So the title is confusing but I can't think of a better way to word it. Basically, I have two taxonomies of "state" and "city" (that have to stay separate for other reasons). Lets say for instance, a term in the taxonomy of "state" is "Connecticut" I then want to display a list of terms from the taxonomy of "city" that populate only from posts with the "state" term as "Connecticut". Basically, I want to dynamically call the state and display the cities in the sidebar on the archive page... I know, this sounds really confusing.
This code works but obviously causes duplicates, I would like each one only listed once.
<?php
$pterms = get_the_terms( $post->ID, 'property_location' );
if ( $pterms && ! is_wp_error( $pterms ) ) :
$prop_links = array();
foreach ( $pterms as $el_term ) {
$prop_links[] = $el_term->name;
}
$st_location = join( ", ", $prop_links );
?>
<?php endif; ?>
<?php endwhile; ?>
<!-- this is a separate loop -->
<?php
$args = array(
'post_type' => 'property',
'post_status' => 'publish',
'posts_per_page' => -1,
'property_location' => ''.$st_location.''
);
$the_query = new WP_Query( $args ); ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<p><?php echo get_the_term_list( $post->ID, 'city', '', '', '' ); ?></p>
<?php endwhile; ?>
Any suggestions?