MarcC Posted July 17, 2013 Share Posted July 17, 2013 I have this task: For any page with "event" template and a date field that is showing a date older than date N, unpublish the event. I need this to happen fairly regularly--is this a good task for lazy cron? Thanks! Link to comment Share on other sites More sharing options...
Alessio Dal Bianco Posted July 17, 2013 Share Posted July 17, 2013 Hi MarcC, maybe this module could be useful: http://modules.processwire.com/modules/schedule-pages/ 1 Link to comment Share on other sites More sharing options...
MarcC Posted July 18, 2013 Author Share Posted July 18, 2013 Thanks Alessio! Link to comment Share on other sites More sharing options...
ryan Posted July 20, 2013 Share Posted July 20, 2013 Just add something like this to the top of your events index page. You could compartmentalize this into a LazyCron call, but for such a simple thing it's really not necessary. $events = $pages->find('parent=/events/, date<"-3 months"'); foreach($events as $event) { $event->of(false); $event->addStatus(Page::statusUnpublished); $event->save(); } Btw, when testing something out like this, always comment out the $event->save(); the first time and take a look at what pages get affected by echoing them rather than saving them, the first time around. i.e. // $event->save(); echo "<p>Unpublishing: $event->url</p>"; Once confirmed that it is behaving the way you want, then remove the echo and uncomment your save(); 9 Link to comment Share on other sites More sharing options...
MarcC Posted July 22, 2013 Author Share Posted July 22, 2013 Nice one, Ryan! Thanks for the tip on echoing before save, too. 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