What are the relationships and arguments in Views? How do I use them? I have read some tutorials, but still don't know how to use them. Can someone explain them more clearly? Thank you.


Relationships are the way Views expresses SQL joins. For example, when viewing a node, you can add a relationship to it's author, pulling in even more data.

Arguments have been renamed "Contextual Filters" in Views 7.x-3.x, which is a better name. Basically, it's a filter that gets its input from the the page, either by the page's URL or the node or user being viewed, etc.


Arguments (or, as mentioned, Contextual Filters) are an incredibly powerful tool in making views context aware. Aside from using the current node, taxonomy term, path, etc. to filter your data, you can use Views arguments in conjunction with the Panels module to create really complex page layouts. The degree to which you can do this with just Views varies based on what you want, though.

Let's say you want a user who goes to /category/books/ to see all nodes or content type 'book', but when he opens /category/malbum/, he should see all nodes of content type 'album' (or tagged with taxonomy term 'album', for example). Without Contextual Filters, you'd have to create two separate views. But if you add the path, taxonomy term, or whatever else you use to mark a node as 'book' as an argument, you can create a single view that does all this AND that accomodate future categories.

With relationships it gets even better. Every book/album has an 'author'. If you want to add, say, the age of the author to the view, you can't do this without relationships, as 'age' is part of an author node, not the book node. In this case you create a relationship, and then you can add the 'age' field from the author content type, as if it was a field in your book node.

The specifics of how to do these things are explained in a number articles and videos, but conceptually I hope this will help you understand it a bit better.


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.