Jump to content

Upcoming Events List


SoccerGuy3
 Share

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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

Greetings,

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.

Thanks,

Matthew

  • Like 1
Link to comment
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
 Share

×
×
  • Create New...