Jump to content

Date in selector issue

Recommended Posts

Hi Everyone,

Any help is appreciated.

I'm trying to get either current and future events (pages) or past ones and am getting an error.

Here's my code ...

if ($page->showPastEvents) {
    $items = $pages->find("template=event, eventStartDate < today, limit=$page->numberOfItemsPerPage, sort=-date");
} else {
    $items = $pages->find("template=event, eventStartDate >= today, limit=$page->numberOfItemsPerPage, sort=-date");

I've also tried this:

$today = strtotime(date('Y-m-d'));
if ($page->showPastEvents) {
    $items = $pages->find("template=event, eventStartDate < $today, limit=$page->numberOfItemsPerPage, sort=-date");
} else {
    $items = $pages->find("template=event, eventStartDate >= $today, limit=$page->numberOfItemsPerPage, sort=-date");

And here's the error I'm getting, thoughts?

Error:     Exception: Unknown Selector operator: '' -- was your selector
value properly escaped? (in
line 165)

Selectors->create('eventStartDate', '', '>= 1374033600')


#2 /var/www/vhosts/sharespost.com/sharespost.co.v1/wire/core/Pages.php(143): Selectors->__construct('template=event,...')

#3 [internal function]: Pages->___find('template=event,...')

#4 /var/www/vhosts/sharespost.com/sharespost.co.v1/wire/core/Wire.php(271): call_user_func_array(Array, Array)

#5 /var/www/vhosts/sharespost.com/sharespost.co.v1/wire/core/Wire.php(229): Wire->runHooks('find', Array)

#6 /var/www/vhosts/sharespost.com/sharespost.co.v1/site/templates/basic-page-events.php(12): Wire->__call('find', Array)

#7 /var/www/vhosts/sharespost.com/sharespost.co.v1/site/templates

Share this post

Link to post
Share on other sites

Updated the "date" in sort. Here's the latest code but still not working. Thoughts?

$today = strtotime(date('Y-m-d'));
if ($page->showPastEvents) {
    $items = $pages->find("template=event, eventStartDate < $today, limit=$page->numberOfItemsPerPage, sort=-eventStartDate");
} else {
    $items = $pages->find("template=event, eventStartDate >= $today, limit=$page->numberOfItemsPerPage, sort=-eventStartDate");

Share this post

Link to post
Share on other sites

Yup, that was the problem. Thank you so much. 

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 Roberts R
      I have simple page structure:
      category subcategory simple-product simple-product simple-product simple-product subcategory .... category2 so Im at category page and running
      $pages->find("template=simple-product, has_parent=$page, limit=8"); and it returns 0 pages
      but this returns 4 pages
      $pages->find("template=simple-product, has_parent=$page"); Can someone explain why limit does not work here?
      So I did some tests and it seems that any limit=n where n is >= actual page count that is possible ... selector return 0 results.
    • 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 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
      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...