We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6059
    • 45 Posts
    Hy, i tried to make a condition where i call this code, in the first line i get all child id in depth 1 where parent = x.

    After that i want to make a query where first check if template = x AND deleted = 0 and published = 1 and parent in ($childs). But how can i check first that i get all these params and than filter it by the child ids?

    $childs = $modx->getChildIds($_GET['p'], '1');
    
    $c = $modx->newQuery('modResource');
      $c->select('id, pagetitle, createdby, parent, publishedon, editedon, alias'); 
      $c->andCondition(array(
        'template' => $_GET['t'],
        'deleted' => 0,
        'published' => 1
      
    $c->sortby('template','ASC');
    $c->limit(15);
    $elements = $modx->getCollection('modResource',$c);
    
    ));
      • 3749
      • 24,544 Posts
      Quote from: cschimanski at Mar 05, 2011, 09:36 PM

      Hy, i tried to make a condition where i call this code, in the first line i get all child id in depth 1 where parent = x.

      After that i want to make a query where first check if template = x AND deleted = 0 and published = 1 and parent in ($childs). But how can i check first that i get all these params and than filter it by the child ids?

      I don’t think getChildIds() will help you. I think you want something more like this:


      <?php
      $c = $modx->newQuery('modResource', array('template'=>$_GET['t'], 'parent'=>$_GET['p'], 'published'=>'1', 'deleted'=>'0'));
      $c->select('id, pagetitle, createdby, parent, publishedon, editedon, alias, template'); 
        
      $c->sortby('template','ASC');
      $c->limit(15);
      $elements = $modx->getCollection('modResource',$c);
      


      If you’re going to sort by template, it needs to be in your select() list.
        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
        • 6059
        • 45 Posts
        I need getchildids because i want only datarows where the parent is in the childs list thats important.
          • 3749
          • 24,544 Posts
          Try the code I posted. If I’m understanding you, it does that with ’parent’=>.
            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
            • 29019 ☆ A M B ☆
            • 104 Posts
            It looks like he’s trying to find grandchildren, not children. He wants to compare the parent with $childs, not the id.

            I’m not sure exactly what getChildIds() returns, but you might try an in() comparison, something like this:

            'parent:IN' => $childs


            Assuming $childs is an array of integers.
              www.darkstardesign.com

              Are you in the Nashville area? Join us for our next MODX meetup!
              • 22303 MODX Staff
              • 10,725 Posts
              You also need to select the class_key column; without this, the objects returned in the collection will not be of the proper derivative class, e.g. modDocument, modWebLink, modStaticResource, etc. You may want the context_key as well.
                • 6059
                • 45 Posts
                Quote from: OpenGeek at Mar 06, 2011, 02:28 PM

                You also need to select the class_key column; without this, the objects returned in the collection will not be of the proper derivative class, e.g. modDocument, modWebLink, modStaticResource, etc. You may want the context_key as well.

                I am new to modx so can you give me a code sample what you mean please?
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: cschimanski at Mar 07, 2011, 01:20 AM

                  Quote from: OpenGeek at Mar 06, 2011, 02:28 PM

                  You also need to select the class_key column; without this, the objects returned in the collection will not be of the proper derivative class, e.g. modDocument, modWebLink, modStaticResource, etc. You may want the context_key as well.

                  I am new to modx so can you give me a code sample what you mean please?
                  $c->select('id,pagetitle,createdby,parent,publishedon,editedon,alias,template,context_key,class_key');

                    • 6059
                    • 45 Posts
                    Ok i know now what you mean, thanks.

                    Is there a modx function called "prepareForIn"?

                    I want to make something like "where parent in (array(’3’,’4’,’5’,’6’,’7’,’8’))"

                    I need to check wich oobject has a parent i get before with getChildIds.
                      • 4172
                      • 5,888 Posts
                      thy this:

                      $c->where(array('parent:IN' =>array('3','4','5','6','7','8')));
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!