Answer the question
In order to leave comments, you need to log in
WordPress. How to display posts belonging to 2 different taxonomies?
Dear connoisseurs, there is a custom post type, which is the text of a song belonging to two custom taxonomies Artist and Album.
The task is to display on the taxonomy-artist.php page all the posts (in the form of links, of course) owned by the Artist and sorted by Album.
In other words, the page should contain the name of the Album and the lyrics posts belonging to it:
Artist Such-and-such
Album 1:
- Lyrics 1
- Lyrics 2
..
- Lyrics 10
...
Album 10:
- Lyrics 1
- Lyrics 2
..
- Lyrics 10
Did not find a suitable function. How to implement?
Answer the question
In order to leave comments, you need to log in
I would use the "Posts2Posts" or "Advanced Custom Fields" plugin (depends on the level of flexibility you want).
Would make 3 types of data:
- song (or lyrics - whichever you prefer)
- album
- artist
Connect these 3 types of data with the right links (again depends on the level of flexibility).
And then in the single-artist.php template
- we request all the albums of the artist
- we run through them in a loop
- in which we request all the attached texts for each album
- we run through the received texts in a loop and display links to them
Taxonomies in WP are so inflexible for tasks like yours... The only negative in my version is the possibly lower performance of all these queries and loops. But transparent structure.
this can be done with built-in methods, but it is ugly and with several requests. It is better to implement this immediately in mysql via wpdb
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question