4

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?

1 Answer 1

5

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
}
2
  • Gave me what I wanted. Unfortunately WordPress doesn't support queries for multiple custom taxonomies without some SQL hackery (LEFT JOIN...). Commented Oct 4, 2010 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
    Commented Oct 4, 2010 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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