Skip Navigation

[Resolved] Group Views results by year and month for posts with multiple dates

This support ticket is created 2 years, 8 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 7 replies, has 2 voices.

Last updated by michaelD-32 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2335105

Hello,

I am creating a view and I wanted to group the results by year and month.
I followed this tutorial and registered the custom shortcode, which worked fine: https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/
I have a custom field for dates, so I just used that, instead of the post date and it works well.
So far, so good.

But there is a problem: The view needs to display events and most of them take place on multiple days in different months.
The user alexK-15 commented about this, but didn't receive an answer: https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/#comment-294540

How can I go on about this? Would you be able to provide a code snipped to fix my problem?
I am using the Classic editor and not Gutenberg, because our main editor is WPBakery.

Thank you and kind regards.

#2335107

This is the code I used.
Unfortunately I don't have enough experience to make it do what I want.
Any help with it would be highly appreciated.

Thanks!

//group by month and year
add_shortcode('heading', 'my_heading');
  
function my_heading($atts, $content = '') {
  static $year = null;
  static $month = null;
  $condition = $atts['condition'];;
  $value = $atts['value'];;
  switch ($condition) {
    case 'year':
    case 'month':
      if ($$condition != $value) {
        $$condition = $value;
        return $content;
      }
      break;
  }
  return '';
}
#2335179

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Basically, for the solution shared what happens is view will loop through the posts order by custom date field as as the result it already order by custom date field the results will be available in order form Jan-Dec and we can then use the heading code.

I would like to know that, you have multiple instance date field - correct? If yes, in that case it will not be possible. I will require to understand your setup first. Can you please share problem URL where you are displaying the view as well as admin access details so I can check and see if I can able to share any possible solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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 have set the next reply to private which means only you and I have access to it.

#2335279

Oh, and the code from Ana (group by month and year) is located at the bottom in the functions.php of the active theme.

#2335341

Minesh
Supporter

Languages: English (English )

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

I checked and based on the structure you shared and I see you are using the repeating date field and there is no way to group those posts by month and year.

One solution I can think of is you will have to set your date field as single instance field and then duplicate the event for other date as well.

For instance:
=> hidden link

See the above event, You have set the event date to march 24,25,26 and April 21.

You will require to create event post for every date.
- Palliative Care Ethics (3 x 20 UE) and set date March 24
- Palliative Care Ethics (3 x 20 UE) and set date March 25
- Palliative Care Ethics (3 x 20 UE) and set date March 26
- Palliative Care Ethics (3 x 20 UE) and set date April 21

So, instead on having 1 post and assign multiple dates to it using repeating field, you will have to create a post per date(that means you will have to duplicate your post and set date).

You should try to give a try for 1 post and see if it displays correctly, if yes, then you can go and duplicate every post per date.

#2336951

Hello Minesh,
thank you for checking! I want to avoid that option to be honest.

Drupal basically uses a calendar feature. Is there any way to get this with toolset? I read that there's a feature in development for a few years now. Are there any more updates of this?
Is there any other way or is installing a plugin like "The Events Calendar" (https://toolset.com/forums/topic/calendar-view/#post-1704825) the only way?

Another thing: How do I disable the troubleshooting Views/Content-Templates Popup?
Since you logged in, it always appears when I open a page (frontend) where Toolset is active. I use firefox.

Thank you and have a nice weekend!

#2336979

Minesh
Supporter

Languages: English (English )

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

Drupal basically uses a calendar feature. Is there any way to get this with toolset? I read that there's a feature in development for a few years now. Are there any more updates of this?
Is there any other way or is installing a plugin like "The Events Calendar" (https://toolset.com/forums/topic/calendar-view/#post-1704825) the only way?
==>
There was a plan to build a calendar view but its not put in action yet:
- https://toolset.com/2019/06/do-you-need-calendar-view-for-toolset/

You should try to install the "The Events Calendar" plugin and check if you able to order events as per your requirement using that plugin without using Toolset.

Another thing: How do I disable the troubleshooting Views/Content-Templates Popup?
==>
I've disabled the debug popup.
- https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#the-views-debug-tool

There is no calendar feature available with Toolset

#2339707

I'll find a workaround. Thank you!