Hi team I am new to modx , for search i am using adv search, by going through documentation ,I found queryhook we can restrict the results with custom conditions.created a snippet called SchHook.
$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";
}
$pubfromdate='2018-11-01';
$andConditions['modResource.publishedon:>'] = "{$pubfromdate}:numeric";
$andConditions['modResource.id:='] = "{10}:numeric";
if (!empty($andConditions)) {
$qhDeclaration = array(
'qhVersion' => '1.3',
'andConditions' => $andConditions
);
$hook->setQueryHook($qhDeclaration);
}
return true;
Search code:=
[[!AdvSearchForm?
&tpl=`myTpl`
&queryHook=`SchHook`
&debug=`1`
]]
<h2>Results</h2>
<p>[[!AdvSearch? &parents=`12`
]]</p>
[[!AdvSearchHelp]]
Results:--
2017-08-28 16:42:33] (DEBUG in AdvSearch::loadDefaultConfigs @ C:\xampp\htdocs\xxxx\core\components\advsearch\model\advsearch\advsearch.class.php : 113)
[AdvSearch] System environment: Array
(
[MODx version] => 2.5.7-pl
[Php version] => 5.6.31
[MySql version] => 10.1.25-MariaDB
[AdvSearch version] => 2.0.0 beta2
)
[2017-08-28 16:42:33] (DEBUG in AdvSearch::loadDefaultConfigs @ C:\xampp\htdocs\xxxx\core\components\advsearch\model\advsearch\advsearch.class.php : 114)
[AdvSearch] Config parameters before checking: Array
(
[corePath] => C:/xampp/htdocs/xxxx/core/components/advsearch/
[assetsUrl] => assets/components/advsearch/
[chunksPath] => C:/xampp/htdocs/xxxx/core/components/advsearch/elements/chunks/
[modelPath] => C:/xampp/htdocs/xxxx/core/components/advsearch/model/
[addCss] => 1
[addJQuery] => 1
[addJs] => 1
[ajaxResultsId] => 0
[asId] => as0
[clearDefault] => 1
[debug] => 1
[help] => 1
[jsSearchForm] => assets/components/advsearch/js/advsearchform.min.js
[jsJQuery] => assets/components/advsearch/js/jquery-1.7.1.min.js
[landing] => 0
[liveSearch] => 0
[method] => GET
[opacity] => 1
[searchIndex] => search
[toPlaceholder] =>
[tpl] => myTpl
[urlScheme] => -1
[withAjax] => 0
[queryHook] => SchHook
[charset] => UTF-8
)
[2017-08-28 16:42:33] (DEBUG in AdvSearchForm::output @ C:\xampp\htdocs\xxxx\core\components\advsearch\model\advsearch\advsearchform.class.php : 315)
[AdvSearch] Elapsed time:0.0315s
Results
[2017-08-28 16:42:33] (WARN @ C:\xampp\htdocs\xxxx\core\cache\includes\elements\modsnippet\54.include.cache.php : 31)
PHP notice: Undefined index: asId
[2017-08-28 16:42:33] (WARN @ C:\xampp\htdocs\xxxx\core\components\advsearch\controllers\advsearch.mysql.controller.class.php : 143)
PHP notice: Undefined index: hideContainers
[2017-08-28 16:42:33] (WARN @ C:\xampp\htdocs\xxxx\core\components\advsearch\model\advsearch\advsearchrequest.class.php : 354)
PHP notice: Undefined index: moreResults
1 - 7 / 7
1. Event 7
2. Event 1
3. EVENT 6
4. Event 5
5. EVENT 4
6. Event 3
7. Event 2
1 - 7 / 7
Please any one can suggest, what Iam doing wrong here, my query hook is not working.Any depdent extra needs to be installed. ?