Jim Yost Posted February 12, 2011 Share Posted February 12, 2011 Hi, I am trying to return 3 random images from an image field using getRandom(3). It appears to be returning all 6 results. I do have only 6 images uploaded to the field. <?php $images = $page->images->getRandom(3); foreach($images as $image) { $thumbnail = $image->size(118,112); echo "<a href='{$image->url}'><img class='photo' src='{$thumbnail->url}' alt='{$image->description}' /></a>"; } I initially thought it was a problem with WireArray, however the following works as expected. <?php $test_pages = $pages->get("/")->children->getRandom(3); foreach($test_pages as $test) { echo $test->name . "<br />"; } Any ideas? -Jim Link to comment Share on other sites More sharing options...
ryan Posted February 13, 2011 Share Posted February 13, 2011 Hi Jim, You found a bug! It was in the Pagefiles class in the makeNew() function, which was returning a populated list when it should be been returning a blank one. I have fixed it in the latest commit. Thanks for finding this. https://github.com/ryancramerdesign/ProcessWire/commits/master Ryan Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now