Jump to content

Searching pages with date like someday


Vineet Sawant
 Share

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.

Link to comment
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
Link to comment
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 :)

Link to comment
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
Link to comment
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
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...