How can I limit the output of assets based on this criteria?
- search all entries randomly in section "homes" for only entries with at least one asset image
- limit those results to 8 random assets
I tried this but it does not always show exactly 8 asset images as the random is called first:
{% set assets = craft.assets.limit(null) %}
{% for homesEntry in craft.entries.section('homes').limit(8).order('RAND()') %}
{% if homesEntry.homeImages|length %}
{% set asset = homesEntry.homeImages.first() %}
{% if asset %}
<a href="{{ homesEntry.url }}"><img src="{{ asset.url('homeImages') }}" alt="{{ asset.title }}"></a>
{% endif %}
{% endif %}
{% endfor %}
Any help is appreciated.