- I have 2 customs post type : “Artist” and “Concert”,
- the “Concert” custom post type is the child of the “Artist” custom post type,
- the “Artist” custom post type has a “genre” taxonomy.
What I’m trying to do (for instance): list all the concerts which belong to artists of the “pop” genre.
Here is the query of my dream:
SELECT * FROM posts WHERE post_type = "concert" AND post_parent_term = "pop"
I think currently there is no such thing as post_parent_term, hope I’m wrong …
(I know i can add the “genre” taxonomy to the “Concert” custom post type and voilĂ ! But I’m really curious to know if there is another way to achieve that).
Thanks by advance.
You can do it in two steps:
There’s a post_parent argument in WP_Query, but it doesn’t accept an array, hence the direct query.
The parent page is stored in $post->post_parent
So you can just grab the parent post that way, and then ask it for it’s taxonomy/category/tag info.
Not sure if its the right way but you could create nested loops:
//first get all artists with the term pop