As I said above, you're setting the $output variable in line 11 above, but you're not returning it, so it has no effect (and the value is incorrect). In line 12, your're returning the ID, so that's what you're seeing.
Replace the last two lines with this one line:
$return !empty($child) ? $child->getContent() : 'No Child found');
So the whole snippet will look like this:
<?php
$folder = isset($folder)? $folder:0;
$criteria = $modx->newQuery('modResource');
$criteria->where(array(
'deleted' => 0,
'published' => 1,
'parent' => $folder,
));
$criteria->limit(1);
$criteria->select($modx->getSelectColumns('modResource','modResource','','',array('id','content')));
$criteria->sortby('RAND()');
$child = $modx->getObject('modResource', $criteria);
$index = rand(0, count($messages)-1);
return !empty($child) ? $child->getContent() : 'No Child found';
I added the limit() and select() lines, which should speed things up. Comment them out if it doesn't work.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
[ed. note: BobRay last edited this post 13 years, 6 months ago.]