Jump to content
gmclelland

Upcoming Events Listing Selector

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks @Macrura.  I think I need to simplify things and limit the calendar postings to single day events only that don't span multiple days.  I would need to create multiple calendar postings for an event that spans multiple days.

Share this post


Link to post
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

Share this post


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

Share this post


Link to post
Share on other sites

I think I did, but I can't remember.

I think these links helped me. 

Hope that helps you

 

  • Like 1

Share this post


Link to post
Share on other sites
25 minutes ago, gmclelland said:

For future help, this thread is the most accurate solution in my opinion. Thanks for the reference!

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jds43
      Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site.
      Does anyone know how I could accomplish this? Would I use something like remove() or not()?
       
    • By VeiJari
      Hello forum! 
      Our customer wants to choose only 15 minute intervals in the inputfield Datetime. So the dropdown values would be: 0, 15, 30 and 45.
      Is there an easy way to achieve this?
      Any help is appreciated 🙂
    • By neophron
      Hi,
      I'm looking for a calendar solution. It should be like this: http://www.graalmueritz.net/plan-aurum.php
      The important part is, that the calendar should show 4 different stages:
      1. free
      2. arrival
      3. departure
      4. occupied
      and the actual date.
      This is for a german website. The client wants to manage the calendar be themself.
      I need detailed offers/estimations in €.
       
      thank you, Nikolai
       

    • By Hubris
      Hi there!
      I'm using some page reference fields to create lists of tags, categories, years, etc.. I'm able to find the pages like so:
      $pages->find("template=project, {$filter}={$page->title}"); Which dynamically does something like: 
      $pages->find("template=project, tags=Experimental"); Only if the value (the page name, like "Experimental") starts with letters. If it starts with numbers, find returns nothing.
      Why is this and how can I fix it?
    • By Elchin
      Hi.
      I want select pages where now between date and end_date or now bigger than date and end_date is empty.
      I have five tried variants:
      $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("foo=(date<$start,date_end=''),bar=(date<$start,date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date<$start,(date_end='',date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end=''|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("!date_end|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end>=$start|!date_end,date<$start,sort=-date,limit=12"); All this variants not worked for me and returned zero results.
×
×
  • Create New...