Skip Navigation

Grouping Custom Post Types by date set in custom field

This support ticket is created hace 9 años, 4 meses. 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.

This topic contains 8 respuestas, has 2 mensajes.

Last updated by Caridad hace 9 años, 4 meses.

Assigned support staff: Caridad.

Autor
Mensajes
#92717

Hi there,

I have set up a CPT of "Events" and have created some custom fields, one of which is the Event Date.

I would like to display events 'grouped' by the Event Date - how would I go about this?

Example of what I am trying to achieve is shown below:

Wednesday 28th August
Event 1
Event 2
Event 3

Thursday 29th August
Event 4
Event 5

Friday 30th August
Event 6
Event 7
Event 8

I have set up a development site, if access is required, please let me know.

#92831

Dear Craig,

Look at the solution described in this reply. It uses a custom shortcode. Instead of m/Y you would use d/m/Y

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#92878

Hi Caridad,

Was there supposed to be a link included in your reply, or were you just referring to the "It uses a custom shortcode. Instead of m/Y you would use d/m/Y" part of your response?

If there was no link, where would I add the custom shortcode you mention?

I currently use a custom shortcode of [wpv-view name="Event Listing" cat="music"] on the Music page.

The code for the View "Event Listing" is:

[wpv-layout-start]
[wpv-posts-found]
<!-- wpv-loop-start -->
   <ul>
      <wpv-loop>
         <li>[wpv-post-link]</li>
      </wpv-loop>
   </ul>
<!-- wpv-loop-end -->
[/wpv-posts-found]
[wpv-no-posts-found][wpml-string context="wpv-views"]<strong>No events found</strong>[/wpml-string][/wpv-no-posts-found]
[wpv-layout-end]

regards,
Craig

#92910

Dear Craig,

Excuse me, this is the url:
https://toolset.com/forums/topic/taxonomy-archive-loops-filter-by-taxonomy-and-organize-under-headings/#post-80907

Let me know if you need help adapting it to your needs.

Regards,
Caridad

#92912

Hi Caridad,

Thank you very much for the link.

I will give this a try and report back to you.

Kind regards,

Craig

#93045

Hi Caridad,

I did some tweaking of the code you linked to and you can see the result at hidden link

Once again, stellar support 🙂 I cannot thank you enough.

Craig

#93200

Dear Craig,

Thanks for your positive feedback. Can you paste the new code with the changes to share the solution with other users?

Once again,
Thanks
Caridad

#93201

Hi Caridad,

Sure thing, no problem…

Added to child theme functions.php

/* Custom Shortcode for display of Date in Event Listings */

add_shortcode('eventdate', 'my_eventdate');
function my_eventdate($atts, $content = '') {
  static $condition = null;
  if ($condition != $atts['condition']) {
    $condition = $atts['condition'];
    return $content;
  }
  return '';
}

Meta HTML for the View Layout

[wpv-layout-start]
[wpv-posts-found]
<!-- wpv-loop-start -->
      <wpv-loop>
        [eventdate condition="[types field="date" format="l jS F"]"]
        <h3>[types field="date" format="l jS F"]</h3>
        [/eventdate]
         <div class="event-link">[wpv-post-link]</div>
      </wpv-loop>
<!-- wpv-loop-end -->
[/wpv-posts-found]
[wpv-no-posts-found][wpml-string context="wpv-views"]<strong>No events found</strong>[/wpml-string][/wpv-no-posts-found]
[wpv-layout-end]

Regards,
Craig

#93220

Thanks Craig