I have a CCK content type called "Media Sample" that can contain audio or video files (always only one file per node).
Is there a way to filter a View so that it shows only nodes containing one of the two kinds of files (audio and video)? Or is this a feature request?


Stuart Greenfield’s picture

Component: Miscellaneous » Documentation
Category: support » task

You can do this directly from Views, but it's a little bit tricky to work out the logic. I knew I'd done this once before, and thought I'd written it down, but I can't find so here are the steps...

Assume you have created a content type called "mixed_media" which accepts the files as you describe using CCK FileField, and assuming you have a got a working view that is pulling all the media (audio and video) in to an SWF Tools playlist.

What you need to do is add a filter to your view, but you want to filter using either the extension of the file, or perhaps more usefully the mime type. These aren't available in the default view (assuming it is based on Node) so you need to add a relationship to the files so you can access file data.

In the Views UI click on the '+' next to Relationships.

Put a check in the relevant field that has the fid for the files being uploaded (for example, Content: Mixed media (field_mixed_media) - fid), then click Add, and then Update.

Next click the '+' next to Filters.

Drop down Groups and select File.

You can now access data relating to the files. To filter on audio you could use the file extension, but a more generic solution would be to filter on the mime type where the type starts with 'audio'. To do this check File: Mime type and then click Add.

Change operator to 'Starts with' and value to 'audio'.

You can leave case sensitive checked since the mime type is always lower case.

Click Update.

That's it - the playlist will now be limited to audio. Using the same approach you can create a video view. You could also expose the filter if you wanted to have a "dynamic" view.

Tagging this issue with documentation so I remember to include this in the documentation overhaul.

dtabach’s picture

Status: Active » Fixed

I just followed your directions and now I have my View exactly the way I wanted. (in addition, I finally learned a bit about what that "Relationship" in Views is for). Thank you very much for the clear explanation, and also for this great module.

Stuart Greenfield’s picture

Status: Fixed » Active

Glad it worked!

NB - changing status back to active as a reminder that this documentation still needs to be updated.

ZuluWarrior’s picture

Hi Stuart,

Any idea how to modify the exposed filter into checkboxes for images, audio, video (for example)?

At the moment you get a textfield which while functional, isn't right for the public, as explaining to anonymous users they must type exactly "image" or "audio" into the text filter is not very user friendly...

fadgadget’s picture

Hi i was hoping to show all videos including those on nodes and in comments. Is this possible at all?