Upcoming Events List

Recommended Posts

New to ProcessWire (came over from PyroCMS) and really liking it so far. The flexibility in page building is amazing!

Anyway, as part of the first site I am building I need an Upcoming Events list. After looking through the forums and docs, I ended up building a page with children pages where each child is a different upcoming event. Each child has title, description, start and end date fields. I have the page working and displaying everything now and am very happy! However, I have one last piece that I cannot figure out. How do I filter the events? Specifically, how do I only show upcoming events and not ones that have already ended?

I am displaying individual events with this:

$events = wire('pages')->get("/events/")->children("sort=event_start_date");

$singleevent = $events->first;

With a full list I can do a comparison in a for loop, but would prefer to just return the valid objects in the initial call.

Basically, is there a way to add a "where" ("where event_start_date > $today") type statement?

  • Like 2

Share this post

Link to post
Share on other sites

Hi- this is a very basic version, i can provide more details later, but in short you first define today as a timestamp and then add your selector.

$today = date();
$events = wire('pages')->get("/events/")->children("event_start_date > $today, sort=event_start_date");
  • Like 2

Share this post

Link to post
Share on other sites

This is even better as it's using less or at least more optimized database calls (depending on the exact selector):

$events = wire('pages')->find("parent=/events/, event_start_date>today, sort=event_start_date");
  • Like 2

Share this post

Link to post
Share on other sites


Welcome SoccerGuy3!  I also was a PyroCMS user back when it first came to life (when it was a CI application and Mr. Sturgeon was still actively involved).  PyroCMS is a great system, and I liked it a lot... That is, until I started using ProcessWire!

Looking forward to seeing other questions you have.



  • 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.

  • Similar Content

    • By Mats
      I’m building a simple ticket booking system for our events. I’m considering two different solutions:
      The first approach is creating one page per ticket and a reference to a booking page with the contact info. This should be faster when checking for ticket availability by using $pages->count().
      The other one is a one page per booking with an integer field holding the ticket quantity. Downside is having to use $pages->find() but only having to create one page per booking with the API. 
      My biggest concern is listing the events and the ticket availability for each event, loading all bookings.
      At the most one event has 300 bookings.
      Any ideas are welcome.  
    • By joshuag
      Introducing our newest [commercial] module:
      Processwire Recurring Dates Field & Custom Calendar Module.
      One Field to Recur them ALL…
      A Recurring Dates InputField for your Processwire templates. The InputField you’ve been waiting for.
      Complex RRule date repeating in a simple and fast user interface.
      Use the super simple, & powerful API to output them into your templates.
      <? // easy to get recurring events $events = $recurme->find(); // events for this day $events = $recurme->day(); // events for this week $events = $recurme->week(); // events for this month $events = $recurme->month(); ?> <? // Loop through your events foreach($events as $event){ echo $event->title; echo $event->start_date; echo $event->rrule; echo $event->original->url; ... } ?> Unlimited Custom Calendars.
      Imagine you could create any calendar you wanted on your website. Use recurring events with the Recurme field, or use your own Processwire pages and date fields to render calendars… it’s up to you. Fully customizable. Make as many calendars as you like. Get events from anywhere. Recurme does all the hard date work for you.
      Unlimited Custom Admin Calendars too.
      Hope you like it  ,
       Joshua & Eduardo from 99Lime.

      ## [1.0.1] - 2017-05-29
      ### changed
      - Fixed $options[weekStartDay] offset in Calendar
      - Fixed ->renderCalendar() Blank Days
      - Fixed missing ->renderList() [renderMonth][xAfter]
      - Removed ->renderCalendar() <table> attributes border, border-spacing
      - Fixed ->renderCalendar() excluded dates
      - Fixed rrule-giu.js exclude dates
      - Fixed ->renderList missing space in attr ID
      (shout out to @Juergen for multiple suggestions & feedback).
    • By ---
      So I discovered in this topic (
      ) that I can cancel all hooks after my own hook. Now I want something like that.
      I want my hook which is called on page render to cancel all other events, also the after page render and the before page render methods, is this possible?
      This only need to be done when some conditions are met.
      /** method replaces original page::render method and is called with hook priority one */ method onPageRender (HookEvent $event) { if (my condition is true) { $this->cancelHooks = true; // to cancel all hooks to page::render // how to cancel after Page::render events // how to cancel before Page::render events } } Is this possible at all?
    • By gmclelland
      I'm trying to show upcoming calendar posting pages that have an event_start_datetime and an event_end_datetime.
      The listing should show
      calendar postings greater than or equal to today (no past events unless it has an event_end_datetime that is within 3 days after today) if the calendar posting has an event_end_datetime and is within 3 days of today it should still show even though the event_start_datetime has passed. Ex. an event that spans Wed-Saturday. If today is Friday, I still want to show the event on my calendar.
      Here is the code I have tried:
      $date = date("Y-m-d");// current date $date_start = strtotime( date('Y-m-d') . " 00:00:00"); $date_end = strtotime(date("Y-m-d", strtotime($date)) . " +1 week"); $paginated_calendar_postings = $pages->get("/calendar")->children("template=calendar-posting|community-event,event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime"); But that doesn't return the correct results.
      I've spent all day searching through the forums, but couldn't find an answer.  Any help is appreciated.
      Also is there anyway to format your selector on multiple lines like this:
      $paginated_calendar_postings = $pages->get("/calendar")->children( "template=calendar-posting|community-event, event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime"); It would make it easier to read long selectors.  When I tried it, it didn't work.  I think it even gave the wrong results.