We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    This is an auto-generated support/comment thread for GetChildIds.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Returns all child id's coma seprated
      follow me on twitter: @dimmy01
      • 15791
      • 1 Posts
      Hi,

      I have a problem with the getChildIds function, i want to get back in a document A the child’s id of a document B and make a link to them. But the array is not valid, I can’t get back the element.

      This is my code :
      <?php
      $tab= $modx->getChildIds(16,1); //the document 16 have 3 children (40,41,42)
      
      $n=count($tab);
      echo $n; //result : n=3
      
      echo in_array(40,$tab); //test if 40 is a child is ok
      
      for($i=0;$i<$n;$i++)
      {
      echo $tab[$i]; //but here there is no output
      }
      ?>
      


      Can you help me plz ?
        • 4172
        • 5,888 Posts
        I think the keys of the array are not 0,1,2 and so on, but are the same as the values.

        Try:

        <?php
        $tabs= $modx->getChildIds(16,1); //the document 16 have 3 children (40,41,42)
        
        $n=count($tabs);
        echo $n; //result : n=3
        
        echo in_array(40,$tabs); //test if 40 is a child is ok
        
        print_r($tabs); // show the array with keys and values
        
        foreach($tabs as $tab)
        {
        echo $tab; 
        }
        ?>
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 7231
          • 4,205 Posts
          When this happens I usually do a print_r() or var_dump() and make sure of the array format.

          I got it working by using:
          foreach($tab as $t => $v){
          echo $v.', ';
          }



            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]