We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46396
    • 14 Posts
    $page = $modx->runSnippet('pdoResources', array(
            'parents'        => $parent,
            'limit'          => $limit,
            'offset'         => $offset,
            'includeTVs'     => '1',
            'tvPrefix'       => '',
            'tpl'            => $tpl,
            'processTVs'     =>'1',
            'where'          =>'{"published":"1"}',
            'tvFilters'      =>`myTV==%keyword%||myTV2==%keyword%`         ));
    

    I’m trying to use this snippet to get resources
    How a can get id list of resources from $page.
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      Hello,

      Could you elaborate on what you are trying to accomplish, for example why are you running pdoResources in this manner?
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 3749
        • 24,544 Posts
        You can display the IDs by using the following placeholder in the template:

        [[+id]]


        There's no way I know of, however, for you to "get" them from pdoResources because all it returns is a big bunch of HTML. You could insert something like this in your Tpl chunk:

        {{DocId=[[+id]]}}


        Then you could use regular expressions on $page to find them, save the id, and remove the tags.

        Since you're rolling your own PHP, you could also get them this way:

        $ids = $modx->getChildIds($parent,0);


        That will give you an array containing the IDs of all the resources, even those that are deleted or unpublished. Unfortunately, getChildIds() doesn't have the option to filter resources except by context.

        To filter those, you'd have to do something like this:

        $allIds = array();
        foreach($ids as $id) {
           $doc = $modx->getObject('modResource', $id);
           if ($doc->get('published') && (! $doc->get('deleted'))) {
             $allIds[] = $id;
           }
        }


        This would be fairly slow. There are faster ways to do it, but they would require more complex code.
          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