Smoo

Sorting event pages by date [SOLVED]

Recommended Posts

Hi folks.
Newbie here - on PW for a couple of weeks now (I've been a Drupal developer for over 10 years).

I've created a template for a Meeting and Event item, which has a title, description and date (a Unix timestamp, called "meeting_event_date").
I also have two templates for displaying lists of these things, one more or less full page and the other as a small block with reduced content to be placed on other pages.

So far so good - I can get all the Events pages using $meeting_events = $pages->find("template=meetingevent");
Then I use a foreach to walk $meeting_events and pull out the date, title and description of each event, wrapping them in my markup as I go.

The trouble is they're coming in in date-created order (based on the metadata of the Events pages, I guess) whereas I'd prefer to be able to sort them by the actual Event date (which is a field on the Event).

I could of course pull the Events from $meetings-events apart and push the individual events into an intermediary array, sort that by the timestamp value, and then walk it to pull out the data into my markup, but I can't help feeling there's a better way. Is there a way to sort the $meetings_events array before running the foreach?

I've tried $meeting_events->sort("meeting_event_date");  but that's having no effect.

UPDATE - just needed to wait for the template to re-compile. Apparently that's not instantaneous...? I still need to understand caching in this environment.
The sort() method above worked. Leaving this here in case it helps someone else.

Share this post


Link to post
Share on other sites

I sort on my site straight inside the selector by field 'postDate' which is a datetime field:

<?php
  $entries = $pages->find("template=blog-entry, sort=-postDate");
?>

 

  • Like 3

Share this post


Link to post
Share on other sites
9 minutes ago, Smoo said:

Well that's tidier - thanks. What does the - flag before the field name do?

Hi @Smoo and welcome to the forum btw :)  (if I haven't done that already in another post?!)

The '-' sorts them ascending or descending. In this case, it's newest first.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.