Skip Navigation

[Resolved] List by categories

This thread is resolved. Here is a description of the problem and solution.

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 Mateus Getulio 1 year, 1 month ago.

Assisted by: Mateus Getulio.

Author
Posts
#2650201

Hi! I'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...

Let me know. Thanks!

#2650515

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

Thank you for contacting our support.

Can you please take a look at this very detailed and step-by-step article showing how to create a nested view using taxonomies?

https://toolset.com/2021/11/how-to-build-a-custom-category-tree-with-toolset/

Based on your description of the issue, I believe this will help you to build what you need. If that's not what you wanted to accomplish please give me a heads up and I'll double-check it.

Best,

Mateus

#2650599

Hi Mateus!

Not exactly a category tree is what I'm trying to do, I didn't explain myself well...

What I want is a list of posts sorted by category...

Category 1
Post 1
Post 4
Post 5

Category 2
Post 3
Post 6

Category 3
Post 2
Post 7

My nested view is not working properly and I don't know what I am doing wrong... I would really appreciate your help.

Thanks!

#2650753

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

Thank you for clarifying what you want to accomplish.

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.

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/

Can you give it one more try following these guidelines and tell me the results?

If you come across any roadblocks or issues please let me know and I'll help you.

Best,

Mateus

#2651115

My issue is resolved! Thanks Mateus!