Skip Navigation

[Resolved] Display posts by date with month header

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

Problem:
Display posts by date with month header, how to group posts by month

Solution:
To group posts by month you need to add custom shortcode.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/display-posts-by-date-with-month-header/#post-1208081

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

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

Last updated by peterA-10 5 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1207979

Tell us what you are trying to do? Hi - I am using Types and Views along with Elementor. I am trying to create a Tour Date section for a musician's site similar to Andre Bocelli's site where he has the month listed as a sort of header with all of that months tour dates below it. I am using Types to add a custom date field which I then display in pieces (day is formatted one way then month another way). My problem is I do not know how to list the month as a header for all posts within that month as Bocelli's site does. To make it simple for my client to add Tour Dates I did not want to use two post types 1) Month and 2) Tour Dates and create a one-to-many relationship. Is there any way to display each months tour dates in sections with the name of the month as a header for each section using just one Tour Dates post type? It would need to be completely dynamic as months would continually be generated as my client added upcoming tour dates.

Is there any documentation that you are following? No

Is there a similar example that we can see? hidden link

What is the link to your site? N/A

#1208081

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - the thing is that there is no way to group the existing custom field value and loop through it but I have a workaround to share.

Here is the alternative way, if that may help you:
=> https://toolset.com/2013/10/how-to-group-views-results-by-year-and-month/

As you can see with the above blog post, the posts are group by year and month but it uses the post date.

To modify the above code to use with the custom field. You should use the following shortcode without any change and add it to your current theme's functions.php file:

add_shortcode('heading', 'func_filter_by_month');
 
function func_filter_by_month($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 '';
}

And here is how you should call the shortcode within your view's loop:

<wpv-loop>
          
        [heading condition="month" value="[types field='stud-registration-date' style='text' format='F'][/types]"]
            <h5>[types field='stud-registration-date' style='text' format='F'][/types]</h5>
        [/heading]
  
          <li>    <h4>[wpv-post-title]</h4> </li>
     
        </wpv-loop>

Where:
- Please change the field name stud-registration-date with your original field name.

Do not forget to set your view to order by your custom date field from view's ordering section.

#1208704

That solution worked perfectly. Thank you!