{exp:channel:entries channel="channel1|chanel2|chanel3" search:featured="Yes" limit="1" orderby="random"}
this returns the same entry every time, is it possible to order by random from multiple channels?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
July 01, 2011 6:23am
Subscribe [5]#1 / Jul 01, 2011 6:23am
{exp:channel:entries channel="channel1|chanel2|chanel3" search:featured="Yes" limit="1" orderby="random"}
this returns the same entry every time, is it possible to order by random from multiple channels?
#2 / Jul 01, 2011 6:38am
It does work, if I clear the cache between page requests!
There must be a better solution?
#3 / Jul 01, 2011 1:57pm
Hi, ip. If you’re using caching, that would make sense why it doesn’t work until you clear the cache.
Untested, but you could have the exp:channel:entries loop in a template that isn’t cached. Give it a try. Or cache the bits and pieces inside the template by having them be cached embeds.
#4 / Jul 01, 2011 2:35pm
Hi,
‘Enable caching’ is set to ‘no’ for the template.
I’ve just limited the tag to a single channel and it still seems to require the cache to be cleared, I don’t think it’s caching anywhere else as it works everytime I clear ee’s cache.
For the clear caching to work it has to be the ‘All caches’ option.
#5 / Jul 06, 2011 6:03pm
To get this working I’ve had to retreive more than one entry and then just display the first, but I’d really like to know why it isn’t working correctly.
ie:
{exp:channel:entries channel="news" search:featured="Yes" orderby="random"}
{if count==1}#6 / Jul 07, 2011 4:19pm
Hi ip,
As far as I can tell, that’s normal behavior if you’re using template caching. Have you tried using tag caching instead? That might be a good middle ground between caching and somewhat apparent randomness.
#7 / Jul 21, 2011 9:56am
Hi, apologies for the slow reply.
I’m not using template caching, ‘Enable caching’ is set to ‘no’ for the template.
Is it the case that the fetch is done first and then the returned results are randomised, in which case limiting to 1 would always return the same result? I was assuming that the randomisation would be left to the sql call.
thanks,
ip
#8 / Jul 25, 2011 12:48pm
Hi ip,
If the behavior you expect to see only happens when you clear the cache, then there’s some kind of caching being employed here. Have you taken a look at query caching? Do you have that enabled?
#9 / Jul 25, 2011 1:05pm
hi
‘Enable SQL Query Caching’ is disabled.
thanks,
ip
#10 / Jul 26, 2011 4:36pm
Hi ip,
After you clear all caches and then view the template again, what folders are created under system/expressionengine/cache again?
#11 / Jul 27, 2011 1:41pm
ee_version
sql_cache
thanks,
ip
#12 / Jul 27, 2011 3:31pm
Hi, ip.
sql_cache means you have SQL Query caching turned on. Have you tried turning that off? You can find it via Admin > System Administration > Database Settings.
#13 / Jul 27, 2011 3:42pm
‘Enable SQL Query Caching’ really is set to off, I wasn’t lying!
‘Enable Database Debugging’ is set to on, would that have any effect?
thanks,
ip
#14 / Jul 27, 2011 4:17pm
ip, in your database.php file, what is set for
$db['default']['cache_on']?
#15 / Jul 28, 2011 6:48am
That’s set to false.