0

I created simple custom post type with few taxonomies. I

<?php $query_params = getQueryParams(); $query_params['post_type'] = 'client'; 
    if(isset($query_params['search'])){
        $query_params['post_title_like'] = $query_params['search'];
        unset($query_params['search']);
    }
    $loop = new WP_Query($query_params);
    if($loop->have_posts()) : while($loop->have_posts()): $loop->the_post(); 

    // SOME HTML

    endwhile; endif; ?>

Then I tried to list display taxonomies for each post, by this:

$categories = get_categories("taxonomy=city");

foreach ($categories as $category) :

echo '&lt;li&gt;' . $category->name . '&lt;/li&gt;';

endforeach;

But I always get all created taxonomies, not only selected to post. Any suggestions?

0
<?php get_the_terms( get_the_ID(), 'city' ); ?> 

You can learn more about this function here.

0

Thanks Tomas,

Here is solution for someone, who had same problem:

$citys = get_the_terms( $post->ID, 'city' );                        
if ( $citys && ! is_wp_error( $citys ) ) :  $city_link = array();
    foreach ( $citys as $city ) {
        $city_link[] = '<a href="city/'.$city->slug.'">' . $city->name . '</a>';
    }                       
$cities = join( ", ", $city_link );
endif;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.