Hi all,

I have a node type which is attached to a taxonomy (containing countries) through Content Taxonomy.
I build up a view displaying all nodes of this type, and I would like to be able to display only the one relative to a country (a term in my taxonomy). So I exposed the filter Content Taxonomy. However, nothing happens when I select a country and the full list of nodes remains. I also have another exposed filter (Node reference) which works perfectly.

Does anybody already add this kind of problem and could help me solving it ? (I could of course forget Content Taxonomy and directly attach my taxonomy terms to my node type, but this create other site specific problems)

Thanks,

Comments

light9’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev

subscribe (6.x)

philsward’s picture

I too am wanting to do some sorting based off of my Content Taxonomy views fields. I have my views style set to 'Table' but I don't even have an option for making my CT fields sortable... This would be a nice feature to have.

fractile81’s picture

The ability to do so is there, it's just not immediately obvious.

Although creating a content taxonomy field and throwing it into a table produces a column of term names, Views only sees the data as a bunch of tids. Because of this, allowing the sorting on that column would produce some unintended results.

Instead, you need to create a relationship. Once you've created your Content Taxonomy field, go to your View and add a relationship. Under the "Content" selections, pick the Content Taxonomy field you want sortable. Save that, and now you need to create a new field. Select "Taxonomy: Term" as your field and continue. In the new options and in the "Relationship" dropdown, select the relationship that you just created, make any other changes you'd like, then click the "Update" button.

At this point, you should be able to click your "Style: Table" gear and be able to sort by term name. Just remember to save the changes to the View itself! =)

philsward’s picture

It's kind of funny that you should mention using the relationships for sorting. I did some research on relationships, found this video: http://drewish.com/node/127 and realized that relationships is the way to go for sorting content taxonomy terms (and a slew of other things) :)

Thx for the in-depth reply on how to sort using relationships! I was able to get mine to work perfectly doing the suggested method.

rconstantine’s picture

I'd say this was fixed thanks to #3 though it should be added to the docs.

I also have a question to add...

Does it make sense to somehow add grouping as an option when using the sorting in #3? Use case: given a vocabulary 2-deep with building/department relationships, I'd like to group the terms on a given node so that just one row per node is displayed, but I still want to sort on that row. I would expect the building (the first layer of term) to be first, alphabetically, then the department. In other words, sort on the concatenation of terms where each layer of term adds to the concatenation.

Is this possible now? If not, would it be hard to do? If my customer really wants this, I don't mind making the patch myself. I'm just hoping for a rough idea on how hard this would be from any of you out there who are familiar with this module's code. Perhaps it isn't even possible due to some kind of technical restriction that you know about.

chaloalvarezj’s picture

subscribing so as to not forget about this!

alex.k’s picture

Great tip in #3, thank you.

For those interested, you can extend this a little bit to sort not alphabetically, but by term weight. That'll allow you to reorder terms at admin/content/taxonomy and have the sorting respect that order. Useful for sequences like "low, medium, high".

Add the relationship, and per instructions above, add the "Taxonomy: Term" field. Also, add the "Taxonomy: Weight" field. Configure the Term field as you need it, and check "Exclude from display".

On the Weight field, check "Rewrite the output of this field", and enter the token for the term field you have above. The naming convention isn't very nice in that it's hard to tell which field is the one you need. For me they looked like "[name_1]", "[name_2]", etc.

Now the weight field is what Views is showing and doing sorting on, but thanks to the rewrite the Term field is actually displayed.

drewish’s picture

Status: Active » Fixed

i guess it's safe to close this.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dgastudio’s picture

thanks.

mehoo462’s picture

Status: Closed (fixed) » Needs review

This is causing duplicate and triplicate node entries in my view when I sort using the taxonomy term.

For example, my view has 5 nodes in it. Then when I sort by taxonomy term, it expands to 18 nodes. Each of the initial five have been repeated between two and four times.

I think I followed the directions in number three exactly. Has anybody else encountered this problem?

I think it might be related to this issue: http://drupal.org/node/584114.

But it seems like this is the workaround for that issue.

mehoo462’s picture

I did some more testing.

Each of my pages have 3 or 4 taxonomy terms. When I sort by taxonomy term it adds a duplicate entry of the node for every term associated with that node. But each redundant entry only shows the term from the content_taxonomy field.

So terms displayed by the "Taxonomy: Terms" field are limited to the terms associated with the content_taxonomy field specified by the relationship.
But sorting by Taxonomy: Terms still creates an entry in the table for each term applied to the node.

This solution works if you only have one term on the node. But if you have multiple terms on the node you will see a redundant entries each term the node has.

Any suggestions for sorting by term when nodes have multiple terms on them?

I think it's related to this issuehttp://drupal.org/node/345571

alex.k’s picture

Status: Needs review » Active

I don't think you can sort on any multi-valued field, because of how it fetches the data. Either you get multiple rows, sortable, or it gets the multiple-valued fields while rendering the view. In both cases it's not clear how you would even sort it, which value to use as the sort key.

mehoo462’s picture

Status: Active » Closed (fixed)

Yeah, never mind. I discovered that what I was trying to make Views do was inappropriate for the task. I found a workaround which is actually based on a better logical understanding of the how the information is organized.

I recommend to anybody trying to Sort a view of taxonomy terms to seriously consider the roles of meta-data and data in your system. Are you trying to view classifications of nodes, or properties of the nodes?

kclarkson’s picture

#3

thank you sirrrrrrr

drupalfan81’s picture

Fractile81, awesome post man! I have been looking for this forever. Great job!

tsaorin’s picture

This solution works. Relations is the solution. Easy and clean.
Thanks #3