We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31303
    • 18 Posts
    take a look of this http://rtfm.modx.com/display/revolution20/Snippets (especially "Example DB Code")


    $c = $modx->newQuery('modResource');
    $c->where(array(
       'parent:IN' => array(12),
       'deleted' => false,
       'hidemenu' => false,
       'published' => true,
    ));
    $c->sortby('menuindex','ASC');
    $c->limit(10);
    [b]$resources[/b] = $modx->getCollection('modResource',$c);
    

    how can i get titles,descriptions,content, TV from that $resources? when i use foreach to print only 1 loops, its just returning damned XPDOObject instead 4 documents inside resource ID 12.

    n.b: for the future docs example, please provide output too, not all users love to spend all time for just finding outputs, thanx
      • 28215
      • 4,149 Posts
      splittingred Reply #2, 16 years ago
      $c = $modx->newQuery('modResource');
      $c->where(array(
         'parent:IN' => array(12),
         'deleted' => false,
         'hidemenu' => false,
         'published' => true,
      ));
      $c->sortby('menuindex','ASC');
      $c->limit(10);
      $resources = $modx->getCollection('modResource',$c);
      
      foreach ($resources as $resource) {
           $pagetitle = $resource->get('pagetitle');
           $description = $resource->get('description');
           $content = $resource->getContent();
           /* etc */
      }
      


      If looping over resources is your snippet, you might want to look into getResources, as it is far more efficient and powerful.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com