Sometimes you have to sort something by the count of its relationship or usage. For example, you need to sort a content type by it rating or you need to sort taxonomy terms by its usage in different nodes. The key to solving these problem is to create a relationship and then aggregate it. Aggregation basically binds fields together based on a criteria such as count. Following is an example that shows how to sort taxonomy terms by their usage in different nodes. Suppose you have taxonomy “operating systems” with terms linux, mac, and windows each being used in 70, 30, 33 content types. You want to sort them as follows:

linux 70
windows 33
mac 30

Following are the steps

  1. Structure > Views
  2. Add new view
  3. Give a name. Show=taxonomy terms. type=operating system. Choose block (you can also choose page, block or both based on your requirements). Continue & edit
  4. There should already be a FIELD “Taxonomy term: operating systems”.
  5. Add a RELATIONSHIP, “Taxonomy term: Content with term”. RELATIONSHIP is found under Advanced.
  6. Create an Aggregation “count”. Also under Advanced
  7. Create a new FIELD Content:Title. You should see “(node) count(Content:Title) | Aggregation settings” when you are done. Make sure the aggregation settings are count.
  8. Filter should be “Taxonomy vocabulary: Machine name (= Technologies) | Aggregation settings” with aggregation setting count
  9. Sort criteria should be “(node) COUNT(Content: Title) (desc) | Aggregation settings” with aggregation setting count

Save and verify.

By master