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.

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.

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
share|improve this question
    
This looks like a great project! I've done some music sites myself and I love organizing the data related to music. I think I can be of assistance here, but I need to understand one thing more clearly, what exactly is album media? I think that'll help me wrap my head around this. Also, can you pastebin your current code for single-album.php. –  tollmanz May 2 '11 at 22:02
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks for given me some better direction @Rarst ! I was able to build the dynamic loop and will post the code when I get it debugged. :) –  mattrepublic May 31 '11 at 16:12
add comment

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.