We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24629
    • 370 Posts
    Hi
    I'm using a snippet that uses 'getChildIds()'. I only want it to get the Ids of children that are published.
    I tried this
    $cids = $modx->getChildIds($root, 6, array('context' => 'web','published'=>1));

    but it seems to ingnore the published propertie.
    a) am i doing something wrong here?
    b) what can i pass on in the options array?

    tnx
    Rdg
      • 42602
      • 81 Posts
      You need to use xPDOQuery to fetch them, the published status is no use with the getChildIds directly:

      $cids = $modx->getChildIds($root, 6, array('context' => 'web'));
      $crit = $modx->newQuery('modResource');
      $crit->select($modx->getSelectColumns('modResource', '', '', array('id')));
      $crit->where(array('id:IN' => $cids, 'published' => 1));
      $collection = $modx->getCollection('modResource', $crit);
      $ids = array();
      foreach($collection as $resource) {
          $ids[] = $resource->get('id');
      }
      


      $ids will contain the id's of children with publish status 1. Hopefully there ain't many typos as I wrote this directly to reply field smiley