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
Comment #0.0
knalstaaf CreditAttribution: knalstaaf commentedrelationship
Comment #1
star-szrThank you.
Comment #2
praimmugen CreditAttribution: praimmugen commentedThanks!
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.
Comment #3
noah CreditAttribution: noah commentedThanks, 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.).
Comment #4
snickwit CreditAttribution: snickwit commentedThanks 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!)
Comment #5
jweedman CreditAttribution: jweedman commentedThanks a million. This was bothering me to no end & this took care of it. Drupal Community rocks!
Comment #6
hockey2112 CreditAttribution: hockey2112 commentedI was just about to install Draggable views to accomplish the ordering I needed, but your little trick worked perfectly. Thanks!
Comment #7
thamasThere 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?
Comment #8
escoles CreditAttribution: escoles commentedthamas, i suggest you post a new support request issue on that. It's not clearly related to the topic of this issue.
Comment #9
thamasescoles thanks for your suggestion! I did: #2011064: Click sort table display by term name (more term reference fields, one vocabulary)
Comment #10
knalstaaf CreditAttribution: knalstaaf commentedComment #11
bmunslow CreditAttribution: bmunslow commentedHi,
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:
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.
Comment #11.0
bmunslow CreditAttribution: bmunslow commentedfollowing
Comment #12
knalstaaf CreditAttribution: knalstaaf commentedComment #13
ace11 CreditAttribution: ace11 commentedThanks!
Comment #14
tr-drupal CreditAttribution: tr-drupal commentedHello,
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
conditionrelationship "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 "
ConditionRelationship is required" of the addedconditionrelationship "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"
Comment #15
knalstaaf CreditAttribution: knalstaaf commented@tr-drupal: are you using a relationship as described in the OP?
Comment #16
tr-drupal CreditAttribution: tr-drupal commentedSorry, translated it wrongly. Yes, I do. This part was supposed to say it:
Comment #17
tr-drupal CreditAttribution: tr-drupal commentedIn 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
Comment #18
nikitas CreditAttribution: nikitas commentedJust adding here,
that the "Disable SQL rewriting " in Query Settings should be checked. Took me like 30 minutes till i find out :)
Comment #19
Anonymous (not verified) CreditAttribution: Anonymous commentedThank you @knalstaaf!
This process works like a charm. I'm so glad that I discovered your post on this topic.
Comment #20
criscomTested 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.
Comment #21
dataylor1975 CreditAttribution: dataylor1975 as a volunteer commentedI 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.
Comment #22
digibrill CreditAttribution: digibrill commentedHi, 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.
Comment #23
digibrill CreditAttribution: digibrill commentedHi, I am still having this issue. Has anyone had this issue?
Comment #24
leoraw CreditAttribution: leoraw commentedHere'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.
Comment #25
Jared Nolt CreditAttribution: Jared Nolt commentedThank you @knalstaaf
This was exactly what I was searching for and worked perfectly on my Drupal 7 site.
Comment #26
AnybodyIf 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