I have a content type A that has a node reference to a content type B.

How can I create a view that show A nodes, and either filter by or sort by the number of references to the content type B? (Let's suppose the node reference to B field in A is named field_reference_b)

I'm interested in both filtering and sorting by that criteria.


I could do this using the module Views PHP Filter, but I'm trying to avoid using it as much as possible.

  • add Relationships in views
    – dobeerman
    Apr 13, 2011 at 5:18
  • @dobeerman and what should I do after that? I don't see any difference Apr 13, 2011 at 6:05
  • after that you can use fields of referenced node in fields list, sort or filter settings.
    – dobeerman
    Apr 13, 2011 at 10:20
  • @dobeerman I know I can use those fields, but I'm looking for the number of referenced fields, not the field value. Something like a COUNT in SQL sentences. Apr 13, 2011 at 17:54
  • oh! i see! try to change query in hook_query_alter.
    – dobeerman
    Apr 13, 2011 at 20:23

1 Answer 1


I don't have enough points to leave a simple comment. I haven't tested this yet. However, I think that you need to select in the 'Relationships' section the node reference. This will join the two tables and give the view access to all the fields in both. Then add an argument and when configuring the argument use the relationship you choose. I'm not sure which argument is best to choose but I think that node title is a good one for the summary and then select the Summery, ascending or desc. This actually creates a list of all the possible titles of A with the number of node B attached to each with a number next to is. When the title of node A is clicked in the block or page view it opens the page with node A's title as the big page title and all of fields of B as long as you selected the relationship under each fields setting.

I wish I had time right now to test it. It's only a theory but I'm sure it's the general direction of solving this.

Your Answer

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

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