So I feel like I must be missing something obvious, but I can't find a solution to my situation. I'm trying to sort some nodes by the chosen taxonomy term name. This is Drupal 7, Views 3.

I have a taxonomy vocabulary 'Country' that is setup something like:

Asia
--Bangladesh
--India
--Vietnam
Afria
--Algeria
--Libya
--Nigeria

On the content type ('Partners') I have a taxonomy field called field_country. I happen to be using the Hierarchical Select module to make sure that, for this field, only the deepest levels are chosen (countries, not regions).

So all of that works and I can display the country chosen as a field in the view.

But I can't seem to figure out the correct way to sort by that country name. When I add the field_country field to the sort criteria, the ordering doesn't make sense.

Any suggestions? Is there a magical relationship I have to activate to get the correct sort option available?

Comments

JonMcL’s picture

Never mind. I feel like an idiot today. I've done this before, but just seemed to have a brain issue.

Very simple:

1. Add a relationship with "Taxonomy: Terms on node". Select the country vocabulary.

2. In the sort criteria, select "Taxonomy term: Name" (I believe this gets added by step 1) and make sure the relationship you create is selected.

Barry Madore’s picture

Thanks for taking the time to reply to your own issue with the solution you found. It saved us a ton of frustration. Your issue was a top Google result for our query as we were having the same problem. Since you put in a solution, we did not have to keep digging. So, Thanks!

blairCruz’s picture

Thanks again for posting the solution. All to often people respond with, "nevermind I solved it". This saved me much time.

Ryan258’s picture

The was simply the piece that slipped my mind, thanks for mentioning it!

finedesign’s picture

I also thank you!

bdanin’s picture

Additionally, if you want to show the rendered taxonomy terms, as a visual way of sorting and linking to those, here's how I did that:

  • Under Format, I'm using show: Content | Teaser
  • Format: unformatted list | settings --> click "settings"
  • Check "Force using fields" and click "apply"
  • Add field "(term) Taxonomy term: Rendered Taxonomy term"
  • Click "settings" again under format, and you can now choose this as Grouping field Nr.1
  • Check "Use rendered output to group rows" and click apply
  • Save, and now your output is grouped by row, showing the taxonomy terms

Brian

dlaufer’s picture

Was trying to hack this together and FINALLY found this. Thanks!

ace11’s picture

And if it still not changing the order to be right remember to clear cache!

mhkc’s picture

Even 4 years later your response to your own question has saved me a ton of head banging. Thanks!!

thalemn’s picture

This is a great thread - thanks!

Tom Hale
New Day Web Design
www.newdaywebdesign.com

macsrevenge’s picture

Old thread but thanks! works for me (Drupal8)

nattyweb’s picture

Thanks - done this several times before but still catches me out. Your post formed a great reminder.

mastermint’s picture

Very quick and simple.
Fantastic. Thank you.

langweer’s picture

Thank you for your solution!

thalemn’s picture

Once again, the simple solution can be hard to figure out. Thanks for sharing your own solution.

Tom Hale
New Day Web Design
www.newdaywebdesign.com

jlbrewster47’s picture

Another happy community member! (worked for me).

maskedjellybean’s picture

I just want to say that if you're trying to sort by term name with a Search API index view in Drupal 7, the process is:

  • Edit your Search API index.
  • On the "Fields" tab, scroll to the bottom. In "Add Related Fields", select the taxonomy term reference field you want to sort by and click "Add fields".
  • Some additional fields should now appear above. Look for your field with "» Name" appended. Check the indexed checkbox. Set the type to String. Click Save changes.
  • Reindex.
  • In your view, add a new Sort Criteria. Look for your field with ": Name (indexed)" appended. Add it. Save the view.
  • Your results should now be sorted by term name.
damien_bates’s picture

Hey Thanks for posting this solution. Was a big help!

For those doing the same in Drupal 8 the steps are the same, however the language in View has changed slightly. 

Original instructions with minor D8 changes

Very simple:

1. Add a relationship with "Taxonomy: Terms on node". Select the country vocabulary.

2. In the sort criteria, Add sort criteria, choose "Category Taxonomy term" then select "Name" under Taxonomy term and make sure the relationship you create is selected.