Group Posts by Term on Post Type Archive
-
I have been working on a solution for this for a while and yet to some up with anything that is really good and does not involve multiple queries. Let me outline the background.
I have a Custom Post Type named People (wpmark_person). Essentially this is the for Meet the Team part of a website. The people are group by a custom taxonomy into different people types. My custom taxonomy is called person type (wpmark_person_type) and it has terms such as:
- Senior Leaders
- Instructors
- Office and Admin
I want to the use the post type archive for the person post type to output all of the person posts. To do this I have used
pre_get_posts
in order to setposts_per_page
to-1
. So I now have all the people posts listing on that archive.What I want to do now is to have them sorted (ordered) by person type. Therefore the page would output something like this:
Senior Leaders
– Person 1
– Person 2
Instructors
– Person 3
– Person 4
Office and Admin
– Person 5
– Person 6However I cannot find a good way to sort the query. Therefore I would be left with loop through the posts and adding them to arrays depending on the person type. Then loop through those again in order to output the content for each one.
Any help would be greatly appreciated. Many thanks in advance.
- The topic ‘Group Posts by Term on Post Type Archive’ is closed to new replies.