Reputation: 3067
I am using modx advsearch snippet to list search results.
[[!AdvSearch?
&extractLength=`220`
&queryHook=`ArticleSearchQHook`
&extractEllipsis=`.`
&contexts=`web,tech,data,main`
&tpl=`articleSearchResult`
&perPage=`10`
&minChars=`2`
&withTVs=`docGroup,post_category,post_subcategory,category`
&fields=`pagetitle,longtitle,description,introtext,content,publishedon`]]
i want to show results which are published between given date range. So i am using 2 text boxes with datepicker plugin. I am able to see the selected dates in URl like below
pubfromdate=2012-11-01&pubtodate=2012-12-18&search=tech&sub=Search
How can i filter result based on date range ?
There is another issue, publishedon column stores date in "timestamp" format as you know and my textfields accepts "DMY" format, but thats not a big deal i think, i can handle that issue.
Upvotes: 0
Views: 697
Reputation: 2281
use this hook in queryHook
<?php
$andConditions = array();
if (!empty($_REQUEST['pubfromdate']) && $pubfromdate = strtotime($_REQUEST['pubfromdate'])) {
$andConditions['modResource.publishedon:>'] = "{$pubfromdate}:numeric";
}
if (!empty($_REQUEST['pubtodate']) && $pubtodate = strtotime($_REQUEST['pubtodate'])) {
$andConditions['modResource.publishedon:<'] = "{$pubtodate}:numeric";
}
if (!empty($andConditions)) {
$qhDeclaration = array(
'qhVersion' => '1.2',
'andConditions' => $andConditions
);
$hook->setQueryHook($qhDeclaration);
}
return true;
Upvotes: 1