Query custom posts by multiple custom taxonomies

When you have created a custom post with multiple taxonomies and you want to query this custom post by specifying multiple taxonomies at the same time; the solution turns out to be extraordinarily simple.

Just use the taxonomy indentifier in your query and set the value to what you want it to be:

$posts = query_posts(
   array(
      'post_type' => "book",
      'book_author_tag' => "Tolkien",
      'book_genre_tag' => "Fiction",
   )
);

In the above example we have a custom post type called book and two custom taxonomies for this custom post type called book_author_tag and book_genre_tag. The above query therefore gets all books tagged with “Tolkien” and tagged with “Fiction”.

Bon App├ętit!

Tagged with: