I was a little stuck when trying to sort my items through Views by term weight. I'm posting this in case someone else runs into this.

I couldn't find anything taxonomy related in the sorting criteria of Views. In order to add taxonomy criteria to the sorting criteria you have to add the following relationship: Content: Taxonomy terms on node. Then check the vocabulary of which the terms of the criteria should be based on.

After that, taxonomy related criteria will be available in the sorting criteria, such as Taxonomy term: Weight.

P.S.: Make sure you have actually sorted the terms to a desired order, on their settings page.

Comments

knalstaaf’s picture

Issue summary: View changes

relationship

star-szr’s picture

Thank you.

praimmugen’s picture

Thanks!

Actually, looks to me that if you've already set up a non-alphabetical order to your vocabulary, once you select the term reference field as sorting criteria you don't need to do anything else, the order is already the one you decided for the vocabulary.

Anyway, if you want to have taxonomy term's related informations, like weight or description, you need to set up the relationship.

noah’s picture

Thanks, this is helpful.

Re: #2, until I enabled the relationship and then sorted on "Taxonomy term: Weight", the only term option I had for sorting was tid, so I think you do have to follow this process in order to sort by weight (or name, etc.).

snickwit’s picture

Thanks so much - this worked perfect for me! I was spinning my wheels trying to figure out why I couldn't sort just by adding the field with the sorted taxonomy terms. Doh!

After following your steps creating the relationship in the view, I then configured my sorting by choosing: Taxonomy term: weight which allowed me to sort my view listing staff employees by their job titles (we know how it's important to put those in right order!)

jweedman’s picture

Thanks a million. This was bothering me to no end & this took care of it. Drupal Community rocks!

hockey2112’s picture

I was just about to install Draggable views to accomplish the ordering I needed, but your little trick worked perfectly. Thanks!

thamas’s picture

Title: Sort by term weight (taxonomy) in Views 3 » Sort by term weight or term name (taxonomy) in Views 3
Version: 7.x-3.0-rc3 » 7.x-3.7

There is a node type which has two taxonomy fields using the same vocabulary. Listing the nodes in a table display. The value of both taxonomy fields has to be displayed in its own column (they may have different values) and want to be able click sort the table by term name (using any of the taxonomy columns).

It seems to me that it is not possible without custom coding. Am I right? Or it it is possible to set? How to do it?

escoles’s picture

thamas, i suggest you post a new support request issue on that. It's not clearly related to the topic of this issue.

thamas’s picture

knalstaaf’s picture

Title: Sort by term weight or term name (taxonomy) in Views 3 » Sort by term weight (taxonomy) in Views 3
bmunslow’s picture

Hi,

The proposed solutions don't work when the taxonomy hierarchy has multiple depth levels.

For instance, if you order a vocabulary with this hierarchy by term weight:

  • Term 1 - Weight 1
    • Term 1.1 - Weight 1
    • Term 1.2 - Weight 2
    • Term 1.3 - Weight 3
  • Term 2 - Weight 2

The result is not what's expected:
Term 1
Term 1.1
Term1.2
Term 2
Term 1.3

Term2 should appear after Term 1.3

The only solution I have found to this recursive problem so far is the Lineage module.

Greetings.

bmunslow’s picture

Issue summary: View changes

following

knalstaaf’s picture

Issue summary: View changes
ace11’s picture

Thanks!

tr-drupal’s picture

Hello,

I'm using Drupal 7.37 and am struggling to get the proper sorting by taxonomy terms working.

What I have so far:
- a vocabulary with some terms in a certain order
- a content type, which has a field of the type "reference to taxonomy terms" and the said vocabulary is assigned to this field
- several contents of this content type, which have different terms of the vocabulary assigned to them (only one value allowed, assigned via a dropdown box). The contents are not published.
- a view, that is displaying fields (not the content, although it's the same with displaying the content). The view has two filter conditions: the said content type and "show on front page = no". The view also has the condition relationship "Content: Taxonomy terms on node". As sorting criteria it has "(my_vocablary) Taxonomy term: weight (asc)"

As far as I see, that's how it should be set up according to several guides like the one here, but for some reason it doesn't work. Neither is the sorting correct nor does the result change when I change the order of some vocabulary terms. When doing some research, I've tried the option "Condition Relationship is required" of the added condition relationship "Content: Taxonomy terms on node" and once I save the view with this option activated, there are no items displayed anymore, which looks to me as if the reference to the taxonomy terms is missing for all the contents, although the terms are selectable and assigned to each node...

I've no idea what is wrong here. Does anyone have an idea maybe?

Edit: replaced wronlgy translated "condition" by "relationship"

knalstaaf’s picture

@tr-drupal: are you using a relationship as described in the OP?

tr-drupal’s picture

Sorry, translated it wrongly. Yes, I do. This part was supposed to say it:

[...] The view also has the condition relationship "Content: Taxonomy terms on node". As sorting criteria it has "(my_vocablary) Taxonomy term: weight (asc)"

tr-drupal’s picture

In case someone else is having the same problem, I've finally found the reason... The sorting was just a follow-up issue. The real issue was the apparently not existent relationship within the view. The reason was, that my contents were not published. Full story here: https://www.drupal.org/node/1107028#comment-9998093

nikitas’s picture

Just adding here,
that the "Disable SQL rewriting " in Query Settings should be checked. Took me like 30 minutes till i find out :)

Anonymous’s picture

Thank you @knalstaaf!

This process works like a charm. I'm so glad that I discovered your post on this topic.

criscom’s picture

Tested this on Drupal 8 but it appears to be onyl working partially.

The view is sorted differently but not exactly like the sort order on the taxonomy page. And I get a lot of duplicates which I cannot exclude from the view admin.

dataylor1975’s picture

I tried this on Drupal 8 and got the same duplicate issue that someone mentioned above. I'm guessing this is because I have multiple the taxonomies, and this workaround seems to only apply if you have one taxonomy field on your node type, as the configuration of the relationship in the view does not involve selecting any particular field.

digibrill’s picture

Issue tags: +tags

Hi, I have this issue, but maybe this is a different setup than I have? I have a list of tags in the sidebar on some pages, but they are alphabetical even though I have Taxonomy term: Weight set. If I go to create a Relationship I do not see Content: Taxonomy terms on node though I do see Content with term. I think I am missing something.

digibrill’s picture

Hi, I am still having this issue. Has anyone had this issue?

leoraw’s picture

Here's my experience with Drupal 8 grouping by taxonomy term and then sorting: I got rid of duplicates by clicking on Multiple Field Settings within the term field and turning off display all values in the same row. My big dilemma is/was with sorting: I did create a relationship to the taxonomy term. Then weight showed up under sort. However, the only way I get the terms to sort properly was to drag each one to a new spot within the taxonomy list. Clicking Reset to Alphabetical seemed to mess up my view. The first time I only had 6 terms. Then I did it again, with 33 terms. It took a while to sort properly. Seems like something funky with taxonomy weight in Drupal 8.

Jared Nolt’s picture

Thank you @knalstaaf
This was exactly what I was searching for and worked perfectly on my Drupal 7 site.

Anybody’s picture

If someone needs a combined solution by depth and weight combined, this might be for you: https://www.drupal.org/project/views_term_hierarchy_weight_field