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
As per comment I also see some trouble understanding
album
andalbum media
essence. You are also mixing up terminology a bit withterms
andtaxonomies
(term
is item intaxonomy
).So I am going to focus on your summary and leave to you how to put parts together:
multiple taxonomy query – taxonomy queries got much improved in WP 3.1 and now you can construct very elaborate things with taxonomy parameters.
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 orget_posts()
function are appropriate.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.