0

I hope I can explain this without being too confusing.

I have a site where I have a custom post type that has two custom hierarchical taxonomies ( categories ) and each post also has a meta filed allowing for a true or false.

  • Post 1
    • Meta - True
    • custom_taxonomy 1 - A
    • custom_taxonomy 2 - 1
  • Post 2
    • Meta - True
    • custom_taxonomy 1 - B
    • custom_taxonomy 2 - 2
  • Post 3
    • Meta - False
    • custom_taxonomy 1 - B
    • custom_taxonomy 2 - 1

I have the query working that will show all posts and if custom_taxonomy 1 or custom_taxonomy 2 is selected then will show those or if both are selected.

If at some point Meta is True then a meta_query is added.

What has really stumped me is that I am now being asked to basically group the posts with its custom_taxonomy 1 heading then the posts.

  • custom_taxonomy 1 - A
    • Post 1
  • custom_taxonomy 1 - B
    • Post 2
    • Post 3

Am I better off reworking the object and looping over the posts to get each posts custom taxonomies so that I can manually loop over them?

The one potential issue I thought about was doing this manually means I might not have $loop->the_post() and some other WordPress methods won't be set.

I have been thinking about this for too long and can no longer see clearly.

Any help or direction would be much appreciated!

0

I had miss guided hope that I could use one query that would group the results but in the end, the solution is to look up all custom_taxonomy 1 results passing the slug into the Post query and looping it.

Because of all the different combinations of filters, I had to create a query builder that dealt with this for me.

In principle, these solutions will work. How to group by taxonomy on Custom Post Type archive how to group custom post type posts by custom taxonomy terms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.