Filter a view based on empty Imagefield

Published November 21, 2011

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.

Comments

Thanks a lot for this tip! It solved a problem that was bugging me for a while! ;-)

Submitted by Guest (not verified) on Mon, 11/26/2012 - 04:56

it creates a separate row per node when there is more than one image in a multiple value image field :(

Submitted by Guest (not verified) on Tue, 01/15/2013 - 12:07

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA