Im in the following situation, i have custom post type called Materials which has a custom taxonomy material_category
Then i have a custom post type called Doors with a custom field “material” that relate to one or more materials (specified above)
When i create the single door page i have no problem to get all the related materials and print them out, also at the moment for each materia i get back i loop to get their category, then i store everything in a temporary object, order it by material_category and print it out to obtain somehhing like:
—
Material:
Wood: Walnut, Pine
Marble: White
Lacquered: Matte, Gloss
—
I found this way quiete intensive (the door have multiple custom field with relation to other objects that need the same category getting and grouping action)
so i was looking for a way to (at least) get the post object with its categories so that i dont need to re-query each result.
probably i can filter on ‘acf/fields/post_object/result’ but i cant find how
any suggestion?
Without querying the DB directly there really is not any way to group post by its terms.
You would need to
1) Get the Post IDs in the relationship field.
2) Get a list of all of the terms
3) Do a query with a tax_query for each term and use the post IDs returned in #1 in the “post__in” argument
https://wordpress.stackexchange.com/questions/32902/display-all-posts-in-a-custom-post-type-grouped-by-a-custom-taxonomy