Skip Navigation

[Resolved] Group Views results by year using a date custom field

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

Problem:
Group posts by year using a date custom field

Solution:
Please try to follow the following article:
https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

You can find proposed solutin, in this case, with the following reply:
https://toolset.com/forums/topic/group-views-results-by-year-using-a-date-custom-field/#post-921586

Relevant Documentation:
=> https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

This support ticket is created 6 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by raulE-2 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#921309

I have created with success a view to show some past events using views: hidden link

I can filter by "categories" but I want to add another filter by year (if possible a drop-down with options for 2018, 2017, 2016...). The filter should be based on the custom field ("start day" of the event).

I have looked in https://toolset.com/documentation/user-guides/filtering-views-query-by-date/

but in my case, the date is a custom field (the "start day" of the event) not the post date.

Do you have any tutorial on this, or can you give me a solution for that?

#921586

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please try to follow the following article that will help you to group post by year.
=> https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

As you have date custom field - you should use following shortcode to display the year:

[types field='field-name' style='text' format='Y'][/types]
#921640

Tank you Minesh

I think I didn't use the correct expression in the title of my post.

The solution you give me is a good alternative, but what I really want is filter results by year using a select menu instead grouping the results by year (because it will have lots of events by year).

The filter should be based on the custom date field, not on the post date.

Is that possible?

#921668

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - got it. You want to add the filter.

So, to do so, to display a dropdown for years, either you need to create a taxonomy which will have years as terms and assign this taxonomy to your post type so you will be able to display years as select dropdown.

Once you do that, please share problem URL and access details, as this needs to use view's filter or other hooks to achieve what you are looking for. Please do not forget to mention which custom date field you want to compare against year filter.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#921681

Oh!!!

That is too much complicated 🙁 for a simple situation. I do not want one more field with just the year.

I think in that case I will use to dates field and use the option Between dates.

If I need more help I will open a new ticket.