I need to list nodes sorted by term weight. If the vocabulary is hierarchical then the weight of parent terms should precede the weight of child terms. Like with this vocabulary:
Animals (weight 10)
- Reptiles (weight 3)
-- Turtles (weight 0)
-- Lizards (weight 1)
- Amphibians (weight 5)
-- Frogs (weight 0)
-- Salamanders (weight 1)
Plants (weight 20)
- ...
Should list nodes with (in this sequence):
Reptiles (3), Turtles (0), Lizards (1), Frogs (0), Salamanders (1)
Rather than:
Turtles (0), Frogs (0), Lizards (1), Salamanders (1), Reptiles (3)
Is this possible? A patch for 7.x-3.x-dev for sorting by term weight seems to have been provided a while back. Not sure if it's related - any update on this? Thank you.
Comments
Comment #1
dawehnerThanks, you aren't wasting time. #1239636: Filter Has taxonomy terms (with depth) not working as expected
Comment #2
futurist commentedHow do you mean? This issue refers to sorting whereas the other one refers to filtering. I did try to stick with the views issue queue guidelines, and by no means intend to waste anyone's time. I just need to get a job done and have spent a considerable amount of time trying to figure these out.
Thanks to everyone working on this module.
Comment #3
JohnnyX commentedI also tried to sort my terms by weight but it simply not work! Terms only ordered by term ID!
No change to order by weight?! If no way have to delete all my terms and create again in correct order?!
Comment #4
JohnnyX commentedopened again...
Comment #5
JohnnyX commented@dereine:
The linked issue doen't match the problem here!
But I found another issue a few minutes ago...
#1239278: Sorting problems when grouping results by taxonomy term (can't acheive alphabetical sorting of term names)
@ futurist:
Maybe that issue describes also your problem?
Comment #6
ZuluWarrior commented@ futurist
I achieved this functionality by creating a view of node (contents). I then added a relationship of Taxonomy terms on node.
This exposes Term:Weight in the filters, sort and fields list. So you can add Term:Weight to your sort criterions and away you go!!!
Any use to you?
Comment #7
pandersb commented@ZuluWarrior
Thanks for your advice. It worked as you said. No patches or errors here.
Comment #8
giorgoskI tried #6 but it did not work for me
I have multiple selections for that vocabulary
I am thinking of the following solution
create field for that vocabulary "sortweight"
feel it in using a view and maybe editable fields
then do a simple "term: sortweight" sort
I have the feeling it will work
Comment #9
giorgoskI suppose #6 works but in my case I had a product display with a commerce product referenced which had a term reference field (with multiple selection allowed) which was giving me a headache
I ended up creating an extra field for the taxonomy in question "sortweight"
and only gave value to children terms and not to parent terms (otherwise I would end up with duplicates) in my view
On my view I added the relationship for the taxonomy vocabulary and filtered out all terms with "sortweight" empty and sorted with "sortweight"
hope it helps someone
Comment #10
ZuluWarrior commentedGood stuff GiorgosK.
I should have mentioned my solution only really works with a one to one term reference. Your solution seems good for multiple term entries.
Another option, if your sort follows some sort of logical order (ie, use the term with the highest term ID or use the referenced term with the lowest weight) you could use the computerized field module to calculate the relative sorting value from the relationship and sort by that.
Still if it ain't broke don't fix it! Just when I read your reply I thought a computerized filed may be another alternative so thought I'd reply so that the option is documented, and here's hoping that the solutions described above help people out in the future.
Comment #11
kars-t commentedHi
I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.
Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.