Hi everyone,
Hope someone can help me here.
I am using WP Types plugin to create custom post types. so the thing is i have a post type with doctors and their city and state as custom fields.
so from another post type page i am trying to populate all the cities within a state.
So far i am able to pull the cities corresponding to that state but since i have several doctors in a city the cities repeat themselves.
How can i prevent this to happen so it only displays the city one time?
this is my code
<?php
$states_var = $_GET['states'];
$loop = new WP_Query( array( 'post_type' => 'doctors', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) {
$loop->the_post();
$cities = get_post_meta($post->ID,'wpcf-city');
$states = get_post_meta($post->ID,'wpcf-state');
foreach($states as $state){
if($state == $states_var){
foreach ($cities as $city) {
echo "<a href=\"?cities=main&city=".$city."\">".$city."</a><br />";
}
}
}
}
?>
[No bumping, thank you.]