Site logo

Archived topic

Group custom post type items by year

3 replies · Started by Daniel on March 2, 2023

Viewing posts 1–4 of 4

Hello

I want to make a web in which the entries of a CPT are shown grouped by years as in the image.

Posts grouped by year

I need the list to be dynamic and when I classify the entries in the corresponding year the whole structure is generated in the frontend. That is, I can't use the query loop block to create the listings by year.

I understand that it can be done but it will require some custom code, can you give me an indication of what WP or GP functions I have to look at to do it?

Hi there,

to do that automatically would require a nested loop, ie. a loop within a loop.
And thats not something that the Query Loop supports just yet, its a future Pro feature.

Does it need to be dynamic?
Considering the intervals are yearly, updating that page once a year to duplicate the query loop and change its Data Parameters is all that would be required.

Let me know

Thanks for the answer David,

The listing does need to be dynamic, as it is to group old movies by their release year.

I'll look for information on nested loops and I'm sure I'll find what I need.

Best regards!

There are some forum support topics for similar requests.
I can take a look for something relevant if you want?
Main question here would be if / how the page is paginated? As that can add an extra layer of complexity to nested loops.

Let me know

This archived topic is closed to new replies.