I would like to show the number of nodes referred from a node reference field in Views. For example, if Content type A has a field "related_nodes" that is a node reference to Content type B with unlimited values allowed. How can I get this view:

Title: Content Type A Title
Referred Nodes: Count of nodes referred

Comments

drupalnesia’s picture

Your subject is "Multiple nodes count in Views" but look like you asking about "number of nodes referred from a node reference field in Views".

Can you give a more clear example, so we can answer you with right answer.

shadysamir’s picture

Title: Number of nodes referred from a node reference field in Views » Multiple nodes count in Views

Let me change the title accordingly

My real life example is: Content Type: Album, and Content Type: Song

Album has a node reference field called "Tracks" that refers to Song nodes and unlimited values allowed.

I want to display the number of tracks in that album (number of Song nodes referred in the field)

So the required view fields are:
Album Title
Number of tracks

shadysamir’s picture

Title: Multiple nodes count in Views » Number of nodes referred from a node reference field in Views
drupalnesia’s picture

Title: Multiple nodes count in Views » Number of nodes referred from a node reference field in Views

Node_referencse used for a selectlist, you must manually select the value of Tracks.

If you want Album automatically show the number of its Tracks then I suggest to:
- Install http://drupal.org/project/computed_field
- Create a computed field, named as "Track"
- Use PHP script to return number of tracks/song according to Album ID (you may use $node->nid)

shadysamir’s picture

I will try that, thanks. Wondering how much of a performance hit it will be.

shadysamir’s picture

Status: Active » Closed (fixed)

It works. Thanks. I tested with my code and enhanced to match Counting the number of values in a multi value field and it does the trick. Of course I have to find a way to recalculate the field in all the nodes already there but that's beyond this issue.