In my custom filter I want to implement filtering out items with parents not equal to current doc id (wich looks the same if I just output child docs of the current doc).
So, how am I to get a doc’s id to compare it to resource[’parent’]?
Here is what I was trying to do:
$filters["custom"]["exampleFilter"] = array("parent,artist_category","exampleFilter");
// Variable: $filters["custom"]["exampleFilter"]
// Add the filter exampleFilter to the custom filters
// list with the source pagetitle and the callback
// exampleFilter
if (!function_exists("exampleFilter")) {
// wrap functions in !function_exists statements to ensure that they are not defined twice
// ---------------------------------------------------
// Function: exampleFilter
//
// Takes the resource array for an individual document
// and asks for the return of a 0 or 1 with 0 removing
// the document and 1 leaving it in the result set.
// In this case, if the lower case value of the pagetitle
// is foo, it is removed while all other documents are shown
// ---------------------------------------------------
function exampleFilter($resource) {
$id = $modx->documentObject['id'];
if ($resource['parent'] != $id) {
return 0;
} else {
return 1;
}
}
}
unfortunately it filters out ALL of the items
Thanks in advance for any help!
$modx->documentObject[’id’] is the current MODx document, not the document Ditto is processing. To get that, simply use $resource[’id’]
Mark, I definetely want the id of the current processed document. I need it to check wether $resource[’parent’] is equal to current document id. The problem is however:
echo $modx->documentObject['id'];
will print the correct id from within the filter, but when I use it in condition:
$id = $modx->documentObject['id'];
if ($resource['parent'] != $id) {
return 0;
} else {
return 1;
}
Ditto outputs no documents (and I want the child docs to be shown)
Hi,
function exampleFilter($resource) {
global $modx; // add this
:-)
Yeah! Thanks Helio!
I had a feeling it was about ’global’ statement, but I didn’t know what to globalize exactly:) Now my hybrid categories work like a charm!
Thanks again Mark and Helio