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.

Use case:

I have a custom post type of 'show' for a music venue. In the sidebar we want to display any related 'show' to the current one on single-show.php. They will be related by a custom taxonomy of 'genre'. I figured I could dump the custom taxonomy slugs for a post (might be more than one) into a variable then pass that variable into a custom query for the sidebar post.

Using get_the_term_list() works if there is a single taxonomy but if there are multiple it breaks (of course).

Any thoughts on how to get an array of the custom taxonomy slugs for a give post into a variable?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can do something like the following:

$terms = get_the_terms( $post->id, 'genre' ); // get an array of all the terms as objects.

$terms_slugs = array();

foreach( $terms as $term ) {
    $terms_slugs[] = $term->slug; // save the slugs in an array
}
share|improve this answer
    
Gave me what I wanted. Unfortunately WordPress doesn't support queries for multiple custom taxonomies without some SQL hackery (LEFT JOIN...). –  curtismchale Oct 4 '10 at 17:15
    
In case you are not aware, there is a plugin for querying multiple taxonomies: wordpress.org/extend/plugins/query-multiple-taxonomies –  sorich87 Oct 4 '10 at 17:34
    
thanks I wasn't aware. it will be supported in 3.1 –  curtismchale Oct 7 '10 at 1:09

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.