We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50923
    • 137 Posts
    I have two of getresources rand on one template, both of them are from same parent, but the problem is that posts shown on one i dont want to show on other, is that possible?

    This is frist call
    	                        [[pdoResources?
    				&parents=`5`
    				&tpl=`HomePostsTpl`
    				&includeTVs=`SharePicture,ColorPicker,ShareTeaser`
    				&showHidden=`1` 
    	  			&includeContent=`1`				
    				&sortby=`RAND()`
    				&limit=`5`
    				&resources=`-5`
    				&breakvalue=`1`
    				&classbig=`12`
    				&classsmall=`6`
    				&instance=`1`
    				&where=`{"modResource.isfolder:!=":1}`
    				]]	  


    And this is second
                              [[pdoResources?
    				&parents=`5`
    				&tpl=`HomePostsTpl`
    				&includeTVs=`SharePicture,ColorPicker,ShareTeaser`
    				&showHidden=`1` 
    				&includeContent=`1`
    				&sortby=`RAND()`
    				&limit=`2`
    				&resources=`-5`
    				&breakvalue=`2`
    				&classbig=`12`
    				&classsmall=`12`
    				&instance=`2`
    				&where=`{"modResource.isfolder:!=":1}` 	
    				]]				

      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
      • 37105
      • 194 Posts
      Hi miomir.dancevic,

      The only thing I can think of is to use the parameter &toSeparatePlaceholders to store each result in seperate placeholders like an array. Then loop through these placeholders and compare value to other set of placeholders if value exists.
        Codeplaza Webdesign: for professional websites at low cost
        • 3749
        • 24,544 Posts
        I'd be inclined to use a custom snippet that pulled 12 resources at random with $modx->getCollection(). Then loop through them to select the first 5 and keep an array of their IDs, putting the results in one placeholder. Then continue and compare each ID with the array until you have two more and use those to populate a second placeholder. You'll only have to make one pass through the resources.

        It will be faster if you use the ID as the array key rather than the value:

        $used[$resource->get('id')] = '';


        That way you can use this for the second group:

        if (isset($used[$modx->resource->get('id')])) {
             continue;
         }


          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