Jump to content
Vineet Sawant

Searching pages with date like someday

Recommended Posts

Hello,

I've a date field with date input format as follows:

'l, j F Y h:i A'

I've a code that creates calendar of given month & year.

What I need is, I need to find pages having above field and date as per the generated calendar.

From Soma's one post on forum for similar problem, I've written following code, but it's giving error

$this_date_raw = $list_day."/".date('m')."/".date('Y');
			$this_date = date("l, j F Y h:i A", strtotime($this_date_raw));

			
			$day_shows = $pages->find("show_datetime={$this_date}");

			foreach ($day_shows as $ds): $calendar.= "<p>{$ds->title}</p>"; endforeach;
             

Error is as follows:

Error: Call to a member function find() on a non-object (line 54 of D:\wamp\www\ticketees_site\site\templates\calendar.php) 

Thanks in advance.

Share this post


Link to post
Share on other sites

Hi!

Just a quick suggestion: is that block of code inside a function? If it is, then variable $pages is not accessible there but you need to use wire('pages') instead.

This is because of variable scoping in PHP, see for example http://processwire.com/talk/topic/3056-cant-use-input-urlsegment1-in-a-function-is-this-my-php-weakling-status-showing/ for some more information.

  • Like 1

Share this post


Link to post
Share on other sites

Dear nik,

You are awesome!

The given code is indeed part of a function. Is that why PW's $pages->find() not working?

I checked the link you've given, it seems I've to use wire() function but how do I use it for finding pages? can you help with that?

Thanks for your help, I really appreciate it a lot.

And wish you a very Happy Diwali :)

Share this post


Link to post
Share on other sites

Yes, $pages is not defined and thus the error. Replace this:

$day_shows = $pages->find("show_datetime={$this_date}");

with this:

$day_shows = wire('pages')->find("show_datetime={$this_date}");

And the same goes for other PW variables listed in http://processwire.com/api/variables/. So $page --> wire('page'), $templates --> wire('templates') and so on.

  • Like 2

Share this post


Link to post
Share on other sites

wire('pages') is equivalent to $pages. You use it exactly in the same way:

$day_shows = wire('pages')->find("show_datetime={$this_date}");

Same goes for the other API variables: $page = wire('page'), $input = wire('input'), $session = wire('session'), etc...

Happy Diwali!! (just checked on wikipedia ;))

---------

edit: speedy nik :)

  • Like 2

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 Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
    • By iipa
      Hi!
      I have two Page Reference fields: Category and Subcategory. Category is parent of Subcategory, and can have 0 to n Subcategories. Fields are selected by dropdown selection.
      I'm trying to achieve following logic:
      1. Select Category (obviously works)
      2. Change Subcategory options based on selected Category (this works)
      3. Hide the Subcategory field if Category has no Subcategories (to prevent weird dropdown with nothing to select)
      I have tried to investigate two possible alternatives to achieve step 3:
      A) Make dynamic condition into Subcategory selection's "Only visible if..." field
      B) Make a hook that fires when Category changes, then hides Subcategory field if Category has no children
      So far I haven't been successful in either. Conditions I've tried always lead to hidden field, and I haven't been able to find set up a hook that fires on field change.
      So here's the question (finally): Is there a way to alter field visibility in API, for example in ready.php or inside a hook? In API I could loop through categories, find the ones that have children and then make a selector based on their IDs.
    • 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.
    • By MateThemes
      Hello everyone.
      I have a question that i can't find a way to solve.
      I have following function in _uikit.php 
      $date = $page->get('date|createdStr'); $dateModified = $page->get('datemodified'); But I need to output the $date in to different formats.
      My further function looks like this
      // return the blog post article markup return " <div> <article class='uk-article blog-post $class'> <meta property='name' content='$page->title'> <meta property='author' typeof='Person' content='Arra Lifte Harmanschlag'> <meta property='dateModified' content='$dateModified'> <meta property='datePublished' content='$date'> <meta class='uk-margin-remove-adjacent' property='articleSection' content='News'> <div property='image' typeof='ImageObject'> $featuredBlogPostImage </div> $heading <ul class='mt25 uk-margin-remove-bottom uk-subnav uk-subnav-divider'> <li class='uk-article-meta'> <time datetime='$date'>$byline</time> </li> </ul> <div class='mt25' property='text'> $body </div> </article> </div> "; Now I need to output the meta property in this format 2019-03-02CET05:23:00 and then a normal date format that is displayed on the Homepage with 2. März 2019 without time.
      Can anybody help me?
      Thanks in advance.
    • By schwarzdesign
      I'm working on a news feed that will show the most recent news in a full teaser grid, and all older news as a simpler archive-type list view. My selectors so far:
      $news_full = $page->children("template=news, limit={$page->feed_count_full}"); $news_archive = $page->children("template=news, start={$page->feed_count_full}, limit=9999"); The $page->feed_count_full field controls how many items to show in the teaser grid (I've confirmed it contains the correct value, and the $news_full selector works as intended).
      This works, but I don't like the limit in the second selector. Unfortunately, if I leave it out (i.e. I only specify a start, not a limit), the start is ignored and I get all news instead. Not a big problem as we will never have more than 9999 news, but it still bothers me, as semantically speaking I don't want to set a limit in this case.
      Is this the intended behaviour of start/limit selectors? Is there a cleaner way to specify an offset (start selector) without a limit?
      ProcessWire Version 3.0.123
      Thanks!
×
×
  • Create New...