我正在使用modx advsearch代码段来列出搜索结果。
[[!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`]]
我想显示在给定日期范围之间发布的结果。所以我使用带有datepicker插件的2个文本框。我能够在URl中看到所选日期,如下所示
pubfromdate=2012-11-01&pubtodate=2012-12-18&search=tech&sub=Search
如何根据日期范围过滤结果?
还有另一个问题,如你所知,以“timestamp”格式发布列存储日期,我的文本字段接受“DMY”格式,但我认为这不是什么大问题,我可以处理这个问题。
答案 0 :(得分:1)
在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;