How to dynamically build a multiple taxonomy query loop within a post type’s single loop?

This question is a little different then the others floating around here. The most similar one is “How to get the parent’s taxonomy ?“.

I have a music cms setup that utilizes two post types: album and album media and a few taxonomies: genre, year, and artist. In the footer of every single-album.php post I want to display the corresponding album media template and do this dynamically. There is only one album media post for every one album.

Read More

Both post types are associated with the three taxonomies. How can I write a loop inside another loop that automatically/dynamically obtains the associated taxonomies of it’s parent post type?

For example: An album called “Dark Side of the Moon” is associated with taxonomies rock, 1973, and Pink Floyd. The album media “Dark Side of the Moon” is associated with the same taxonomies.

Within the main loop in single-album.php is another loop that looks for what three taxonomies the album is associated with and constructs a loop for “album-media”. The contents of this loop could also be displayed as single-albummedia.php.

Can this be done? I have the feeling that I am over-thinking this 🙂

Things this question involves:

  • multiple taxonomy query
  • loop within a loop
  • custom taxonomies and post types

Related posts

Leave a Reply

1 comment

  1. As per comment I also see some trouble understanding album and album media essence. You are also mixing up terminology a bit with terms and taxonomies (term is item in taxonomy).

    So I am going to focus on your summary and leave to you how to put parts together:

    1. multiple taxonomy query – taxonomy queries got much improved in WP 3.1 and now you can construct very elaborate things with taxonomy parameters.

    2. loop within a loop – easier to say secondary loop, it doesn’t matter where secondary loop is. because it shouldn’t influence surroundings in any case. For secondary loops either WP_Query object or get_posts() function are appropriate.

    3. custom taxonomies and post types a little to generic point, there are plenty of nifty related functions. I suppose wp_get_post_terms() sees a lot of usage, when taxonomies are involved.