I have been searching the MODX Revolution docs but can’t find the answer. How can I change the Unpublish Date for a resource in a snippet? I have a collection of resources that are job listings. There is a Date TV that sets the application deadline and a numeric TV that sets the number of days after the date to display the listing. I have a snippet on the page that displays the listings and will also serve as a checker for setting the Unpublish date.
<?php
/* build a query to get Resources with a parent of 2 that are published and not deleted */
$query = $modx->newQuery('modResource', array('parent' => 81, 'deleted' => false, 'published' => true));
/* to optimize, you can select only the columns you need */
$query->select($modx->getSelectColumns('modResource', 'modResource', '', array('id', 'pagetitle', 'unpub_date')));
/* get the modResource objects with a parent of 81 */
$children = $modx->getCollection('modResource', $query);
/* loop through the children */
foreach ($children as $child) {
$job_listing_application_deadline = $child->getTVValue('job_listing_application_deadline');
$job_listing_post_deadline_display_days = $child->getTVValue('job_listing_post_deadline_display_days');
$delist_date = strtotime(date("Y-m-d H:i:s", strtotime($job_listing_application_deadline)) . " +{$job_listing_post_deadline_display_days} days");
$delist_date = date("Y-m-d H:i:s", $delist_date);
if ($delist_date <> $child->get('unpub_date')) {
$child->set('unpub_date', $delist_date);
}
// more code here that outputs a table with all the listings
}
?>
The line setting the unpublish date doesn’t work, I can’t find the right syntax. Any help greatly appreciated.