All for creating and promoting websites

Layout, programming, web tools

Select material by date in XPDO MODX

Select material by date in XPDO MODX

Working with XPDO in MODX Revo sometimes there is a need to bring materials on a specific date, but there are some nuances, namely, the problem arises from the fact that the database stores dates in a standard format.

Consider a script that displays all of the content for a specific day.

<?php
$data = date('2015-12-10'); // In this variable we recorded the right day
$date_from = strtotime($data." 00:00:00");
$date_to = strtotime($data." 23:59:59");

$data_y = date('Y-m-d',(strtotime('-1 days', strtotime($data))));
$data_t = date('Y-m-d',(strtotime('+1 days', strtotime($data)))); 

$where = $modx->newQuery('modResource');
$where->limit(5); 
$where->where(array(
	'publishedon:>' => $date_from,
	'publishedon:<' => $date_to,
));
$resources = $modx->getCollection('modResource',$where);

$res .= '

Selected day '.$data.'

'; foreach ($resources as $k) { $res .= '

'.$k->get('pagetitle').'

'; $res .= '

Дата: '.$k->get('publishedon').'

'; } print($res);

If you need to bring materials not before a specific day, comment out the following line:

	'publishedon:<' => $date_to,

For example, you can display all materials that were published after "2015-12-10".

And similarly, display of the date no later than a specific number, then comment this line.

	'publishedon:>' => $date_from,

In variable $data, you can pass any date fields in MODX, for example, the publication date or TV date type.

Highlight found mistake and press Ctrl + Enter to notify the administrator.