Pages

Tuesday, February 16, 2016

Filter a view based on empty Imagefield

Turns out there is no filter that asks wether or not an imagefield (or filefield) has a value. I came across this tip on Drupal.org. The recommendation was to use a relationship, and then choose "Require this relationship" to act as a filter. Pretty cool.
So assuming your imagefield is just called "Image", here is the walkthrough:
  1. Add a new view of type "node"
  2. Add one or more fields (I assume you want to include the image field) in the normal way
  3. Click the button next to Relationships to open the dialog for adding relationships
  4. From the "Content" group, choose your Image field (which will be followed by "fid")
  5. Make sure you click the "Require this relationship" box when adding the relationship
That should be it!
I don't know if this changes for Views 3.x and Drupal 7, but this is the only way to do this in Drupal 6 and Views 2.x. You're welcome.

No comments:

Post a Comment

Thanks for your comment.