I want to build a filter for a custom module I built and have integrated with views. In essence, the module allows you to define types of relationships between different nodes. I'd like to create a filter for this so that I can display nodes of a certain type of relationship.

I'm not finding any documentation that describes filters in more detail and explaining the various parts to them. The API documentation is horrific in this regard.

Can anyone suggest a good resource/article on building View Filters in detail?

  • (moved from my answer to a comment) Statements like "The API documentation is horrific in this regard." will not motivate people to give you an answer (Especially not the people who have put in many hours to write the existing views documentation). Keep your questions objective.
    – Berdir
    Mar 8, 2011 at 0:16
  • Once you understand views the documentation is good, however some more how tos (like how to build a views filter) would be very helpful. Mar 8, 2011 at 9:25
  • 1
    @berdir you are correct about keeping the questions objective. The issue is that the existing documentation is not sufficient for helping people understand HOW views in code works, the process flow, what all the functions really mean, and how you should use them. The documentation on logrus is code documentation, which should be a standard practice anyway. I am thankful for their efforts, but left frustrated cause in reality it isn't good enough. More useful documentation will lead to better code, coders, and stronger communities. Though this is not a discussion for this post.
    – lordg
    Mar 8, 2011 at 19:39

5 Answers 5


Have you tried http://views-help.doc.logrus.com/ or the advanced help module?

Unfortunately there is no deeper documentation that I know of. I wrote a custom field handler and got most info from other handlers that came with views. I would recommend looking at the views/handlers directory, especially all files beginning with 'views_handlers_filter_'. At least that is what I did.

  • 1
    Yip. And its not very clear on how to code a filter. It only describes how to describe a filter to views for use. And the logrus documentation is not helpful in understanding how to code a filter and what are the different parts of it.
    – lordg
    Mar 7, 2011 at 20:51
  • 1
    looks like that was the only option. This is certainly the one frustration I've had with Views and drupal. Ok to get started, but as soon as you want to start more advanced building, you have to dig into code and decode what is going on.
    – lordg
    Mar 7, 2011 at 22:53
  • views.doc.logrus.com is great too, I couldn't see a link from the docs to this. Mar 8, 2011 at 14:42

I think the reason that the documentation isn't as deep as you like is that once you get to the level of creating a filter, the onus is on you to understand what that means. The best Views' documentation is the basic filters that already exist. You should look at things like views_handler_filter_string and views_handler_filter_numeric to see how a really basic filter is structured. Most filters inherit from one of these, because most fields ultimately end up needing either string operators or numeric operators.

The second place to look is views/modules/node and check out the node filters. That handles your basic special filters for things like node types. Once you've figured out how the views_handler_filter_in_operator works, that's 99% of filters and you need to very little on your custom filters except use one of those.

  • If that is the real Earl Miles, welcome to drupal.se. Mar 21, 2011 at 17:55

The best documentation on Views API is most likely http://drupal-building-blocks.com/. So that might be an option if you can (and want to) afford it.

As EricSchaefer already said, your best bet except of that book is to use an existing filter that is as close as possible to what you want, copy it to your module, rename and start extending it.

A google search for "drupal create custom views filter" listed this as the first result and that had a link to this, both sound like they could be of use to you.

  • thanks for the links. The first google one had had already found and made use of. The second one looks useful too.
    – lordg
    Mar 8, 2011 at 19:32

Here are the tutorials I found for creating Views filters:

They are pretty basic and you might still be left wondering about what's what. There's no other choice but to go clicking around Views functions and methods to investigate properties, inheritance, etc. If I find more tutorials I'll keep adding them.


There is a 2011 book, "Drupal's Building Blocks: Quickly Building Web Sites with CCK, Views, and Panels", that is excellent.

Also do a search on the web for: 110112-WebformInViews2.mov. It is an excellent step by step movie in creating a View.

Or, just make a copy of your view and filter out what you don't want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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