2

How can I find entries with at least 1 image?

{% set category = craft.categories.group('storyCategories').slug(catSlug).first() %}

{% set params = {
  section : 'stories',
  order : 'postDate desc',
  relatedTo: category,
  limit : '4'
} %}
{% set stories = craft.entries(params).find() %}

I have this, but am not sure how to only get stories entries when the story has an image.

3
  • Do you put your images in relationfields or do you upload them via redactor? The first is really easy – Robin Schambach Dec 6 '17 at 17:16
  • The images are in as asset fields. I've just realised I can do this: {% set params = { section : 'stories', order : 'postDate desc', relatedTo: category, limit : '4', storyImage: ':notempty:' } %} Where "storyImage" is the field name of my image field. – codeandchips Dec 6 '17 at 17:22
  • 1
    Yes indeed. Would you mind adding that as an official answer and mark it as solved for future reference? – Robin Schambach Dec 6 '17 at 17:23
1

I've just realised I can do this:

{% set params = { section : 'stories', order : 'postDate desc', relatedTo: category, limit : '4', storyImage: ':notempty:' } %} 

Where "storyImage" is the field name of my image field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.