Problem:
'm trying to create a category-ordered list like this:
Category 1
Item 1
Item 4
Item 5
Category 2
Item 3
Item 6
Category 3
Item 2
Item 7
I have created a post type with 2 custom fields and also the categories of the post type.
I understand that a nested view must be made. How can I do it? The nested views I made don't work correctly...
Solution:
To display a list of posts sorted by category, in summary you'd need to:
1- Create a view for the categories:
This view will loop through your categories.
2- Inside this view, nest another view for posts:
This nested view will loop through the posts associated with the current category from the outer loop.
3- For the Nested View for Posts:
You need to pass the current category ID from the outer loop to the nested loop, so that it can fetch posts from that category.
Make sure the query for this view is set to filter by the current taxonomy term passed to it.
In some more details:
1- Create the Main View for Categories:
- Add a new view.
- Select the taxonomy (categories) you want to list.
- In the Loop Output, just have a placeholder for where you'll insert the nested view.
2- Create a Nested View for Posts:
- Add a new view.
- This time, choose the post type.
- Under the 'Query Filter', add a filter by taxonomy. Choose the taxonomy (category) and set the value to come from the current page (because we're passing it from the outer view).
3- Integrate the Nested View in the Main View:
- Go back to the main view (categories) and in the Loop Output, where you kept a placeholder, insert the nested view (posts). Ensure you're passing the current taxonomy term ID to it.
Relevant Documentation:
We also have a really nice and detailed tutorial explaining how you can achieve this here: https://toolset.com/2015/07/how-to-group-posts-by-category/
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 |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Sao_Paulo (GMT-03:00)
This topic contains 3 replies, has 2 voices.
Last updated by 1 year, 1 month ago.
Assisted by: Mateus Getulio.