Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a site for an architect and each Project page has a custom taxonomy called Project Services where the client can add various tags. I want to display them in a tag cloud so I'm using this:

<?php wp_tag_cloud( array( 'taxonomy' => 'project_services', 'separator' => ', ') ); ?>

But - the problem is that on each Project page, it's displaying all the various Project Services tags in the database, instead of on a per page basis. Any ideas?

share|improve this question
    
you are welcome and glad it works. However, please don't use answers to leave comments, when you'll get 50+ rep you can comment ;) –  G. M. Oct 17 '13 at 16:08

1 Answer 1

up vote 3 down vote accepted

Is the normal behavior of wp_tag_cloud: it show all tags, not only the tags for a specific post, even if inserted in a singular page. However, that function has an option include that let you define the tags to include (must be comma separed list of tag ids).

So, in your template file, pass that param to wp_tag_cloud using as value the list of tag ids of current post, that you can retrieve using get_the_terms and wp_list_pluck

global $post;
$terms = get_the_terms( $post->ID, 'project_services' );
$tag_list = implode(',', wp_list_pluck($terms, 'term_id') );
$args = array(
  'taxonomy' => 'project_services',
  'separator' => ', ',
  'include' => $tag_list
);
wp_tag_cloud( $args );

In this way only page related tags will be shown in tag cloud.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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