Hello -
I find myself needing to do this on many different sites and after much search I have found the need for some help.
Looking to order custom posts by grouping in category with each category group having a title only once at the beginning of the category group. Like this:
Taxonomy Title 1
- Post
- Post
- Post
Taxonomy TItle 2
- Post
- Post
- Post
The only way I have found to do this is to create a view for each category and place on a page but this is not good if the client adds a new category.
Thanks for your help...
If I understand correctly, this looks like something that must be accomplished with custom code. There is no built-in method that allows you to loop over all the Taxonomies that exist on a site in Views. If you create a Taxonomy View, you can see that it's only possible to show content from a single Taxonomy, and that Taxonomy must be static. In other words, you cannot create a variable View that will display results for multiple Taxonomies. So this is a challenge you will have to overcome with custom code.
The WordPress API get_post_taxonomies can be used to return an array of taxonomies associated with a given post type:
https://codex.wordpress.org/Function_Reference/get_post_taxonomies
You could create a custom shortcode that loops over that array in PHP and outputs the taxonomy Title, then outputs a View of posts filtered by Taxonomy term slugs, passed in by shortcode attribute. Insert all the term slugs from the current taxonomy in the render_view arguments to pass them into the Query filter. Then you can use the wpv_filter_query API to modify the query dynamically to reflect the current taxonomy.
https://toolset.com/documentation/programmer-reference/views-api/#render_view
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query