How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta

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!

Read more here:: How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta

Leave a Reply

Your email address will not be published. Required fields are marked *