formmailer Posted December 1, 2011 Share Posted December 1, 2011 Hi! I am probably thinking totally wrong, but I would like to run the following $pages->find query directly in a module's function $pages->find("status=unpublished"); I don't want to run it in the template and pass the PageArray to this function, but when I am trying this I get the following error: Call to a member function find() on a non-object Is it possible to do this in some way or does it require a totally different approach? /Jasper Link to comment Share on other sites More sharing options...
apeisa Posted December 1, 2011 Share Posted December 1, 2011 This should work everywhere: wire("pages")->find("status=unpublished") Also you can view all unpublished pages through search page also: /processwire/page/search/?q=unpublished&show_options=1&field=status&template=&submit=Submit+Search&operator=%3D&display=&sort=relevance Link to comment Share on other sites More sharing options...
Soma Posted December 1, 2011 Share Posted December 1, 2011 yes, and in modules you can also use $this->pages->find(); $wire->pages->find(); Link to comment Share on other sites More sharing options...
formmailer Posted December 1, 2011 Author Share Posted December 1, 2011 Thanks guys, that did the trick! /Jasper Link to comment Share on other sites More sharing options...
formmailer Posted December 1, 2011 Author Share Posted December 1, 2011 Hmmm... I need to make the find query more complex and I am not sure how I can fix this. I have: wire("pages")->find("status=unpublished, publish_from<" . time() .", publish_until>" . time()); The above works, but I also need the the pages without a publish_until date (publish_until = empty). How can I do that ? Is it possible? /Jasper Link to comment Share on other sites More sharing options...
ryan Posted December 1, 2011 Share Posted December 1, 2011 It sounds like you want publish_until to serve two purposes: as a toggle and as a date. I don't think you can have it do both, but here's a couple alternate approaches: 1. Leave the publish_until out of the selector and check it in your loop afterwards: <?php $time = time(); $matches = wire('pages')->find("status=unpublished, publish_from<$time"); foreach($matches as $m) if($m->publish_until > 0 && $m->publish_until < $time) $matches->remove($m); 2. Or; use two find()s: <?php $time = time(); $matches = wire('pages')->find("status=unpublished, publish_from<$time, publish_until>$time"); $matches->import(wire('pages')->find("status=unpublished, publish_from<$time, publish_until=0"); Link to comment Share on other sites More sharing options...
formmailer Posted December 1, 2011 Author Share Posted December 1, 2011 Thanks Ryan! As you probably understood I am writing a module for scheduled posts and I thought everyting worked, but suddenly I realised that you easily can have pages with a start date but without an end date, so I need to take care of these as well. Just ignoring the end date actually works, but causes expired pages to be activated and be deactivated directly afterwards by the "unpublish rule". I'll try your options out and I am sure they will work. /Jasper Link to comment Share on other sites More sharing options...
Bill Posted March 20, 2012 Share Posted March 20, 2012 Thanks Ryan! As you probably understood I am writing a module for scheduled posts and I thought everyting worked, but suddenly I realised that you easily can have pages with a start date but without an end date, so I need to take care of these as well. Just ignoring the end date actually works, but causes expired pages to be activated and be deactivated directly afterwards by the "unpublish rule". I'll try your options out and I am sure they will work. /Jasper (embarassed to ask... but the shame isn't too deep!) Module completed and available to public? (whistling as if no one heard a thing...) ;P Link to comment Share on other sites More sharing options...
apeisa Posted March 21, 2012 Share Posted March 21, 2012 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now