We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36502 ☆ A M B ☆
    • 491 Posts
    Hi, I'm using a call of getResources like this:

    [[!getResources? &parents=`-1` &resources=`[[my-snippet-filter]]` &tpl=`my-tpl` &limit=`20` &deleted=`0`]]
    


    where [[my-snippet-filter]] get some content id with a query on TV table.

    The problem is: [[my-snippet-filter]] gets also resources deleted (it runs only in TV as said), and getResources displays also them...
    is it possible?

    Is there a way an api call to check if a resource is deleted or not?

    Thanks
      TilliLab | MODX Ambassador
      website
      • 3749
      • 24,544 Posts
      getResources skips deleted resources by default. AFAIK, there is no &deleted property (there is &showDeleted).
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36502 ☆ A M B ☆
        • 491 Posts
        Hi Bob, and thanks for reply,

        the problem is that if you use getResources with the parameter
        &resources=`1,3,5`


        and, let's suppose, resource 3 is deleted, getResources shows it anyway...

        I solved filtering more the target resources, this is my snippet:

        <?php
        $mydate=date('Y-m-d');
        
        $c = $modx->newQuery('modTemplateVarResource');
        $c->where(array(
           'tmplvarid' => '20',
           'value:>' => $mydate,
        ));
        $c->sortby('value','ASC');
        
        $ress = $modx->getCollection('modTemplateVarResource',$c); 
         
        foreach($ress as $result){ 
        
        $target=$result->get('contentid');
        $document = $modx->getObject('modResource',array(
            'id' => $target,
            'deleted' => '0'
        ));
        if ($document) echo $document->get('id').',';
        
        }
        


        I imagine that there is a smarter way to do it...
        but for the moment this works smiley
          TilliLab | MODX Ambassador
          website
          • 3749
          • 24,544 Posts
          That looks good. It should be significantly faster than using getResources, though you should use 'return' rather than 'echo'.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36502 ☆ A M B ☆
            • 491 Posts
            touchè!

            I think I need to read the MODx book smiley

            thanks!
              TilliLab | MODX Ambassador
              website
              • 3749
              • 24,544 Posts
              Yes, actually it would be best if everyone on earth had one or two copies. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting