Display node count per node reference field

Updated: 20 January, 2022 seen 2,793

Previous I wrote - How to display node count per taxonomy. Today I faced a problem displaying node count for a particular node reference field.

The scenario is like this: We have two content types: Destination, Hotel. Each hotel is referenced to a specific destination by using node reference. We need to display how many hotels there are in all destinations.

To achieve such a result, create a new View (content-based), for example, hotels

Relationships:

  • Add node reference field, in our case - field_where

Other:

  • Use aggregation: yes

Fields:

  • (field_where) Content: Title | Aggregation settings
  • (field_where) Field: Background | Aggregation settings (Optional)
  • Content: Category | Aggregation settings(Optional)
  • COUNT(DISTINCT Content: Nid) | Aggregation settings 
  • Global: View result counter | Aggregation settings (Optional)