Jump to content

Upcoming Events Listing Selector


gmclelland
 Share

Recommended Posts

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.

Link to comment
Share on other sites

you can use arrays in selectors now, or if you prefer you can setup the selector parts in a plain array and then implode it with commas , into a variable, e.g. $selector.

also, i believe to make the logic work in your selector, you may need to use OR groups https://processwire.com/api/selectors/#or-groups

you can't do the separate lines within the selector because there would probably be 'junk' like \n, \s, and possibly \t

  • Like 1
Link to comment
Share on other sites

Simple string concatenation also may help:

$selector  = "parent={$myParentContainer}, template=atemplatesname";
$selector .= ", fieldnameOne=1";
if(--someConditionHere--) $selector .= ", fieldnameTwo!=selected";
...
$selector .= ", sort=afieldname, limit=10";

and this:

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
On 3/16/2017 at 5:35 PM, gmclelland said:

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");

 

@gmclelland Did you ever find a solution to this issue? I've been searching the forums for this exact thing and can't find anyone else with this problem. Thanks!

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