We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33114
    • 518 Posts
    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 sad

    Thanks in advance for any help!
      http://modx.ru - российская поддержка MODx
      http://newscup.ru - экспериментальный проект
      http://yentsun.com - персональный сайт
      • 18397
      • 3,250 Posts
      $modx->documentObject[’id’] is the current MODx document, not the document Ditto is processing. To get that, simply use $resource[’id’]
        • 33114
        • 518 Posts
        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)
          http://modx.ru - российская поддержка MODx
          http://newscup.ru - экспериментальный проект
          http://yentsun.com - персональный сайт
          • 11975
          • 2,542 Posts
          Hi,

          function exampleFilter($resource) {
          global $modx; // add this

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 33114
            • 518 Posts
            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 smiley
              http://modx.ru - российская поддержка MODx
              http://newscup.ru - экспериментальный проект
              http://yentsun.com - персональный сайт