Skip Navigation

[Resolved] Display posts ordered by Taxonomy

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#816386

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...

#834000

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