I am trying to filter nodes returned based on a taxonomy term. I don't want to see all the nodes..

My current attempt is using a nodereferrer argument to return nodes that refer to a given node and a field to list the taxonomy terms but the result yields duplicates because many of the these nodes have the same taxonomy term.

I have searched this up and down and the typical suggestions of use "all terms" and "distinct yes" just don't work. Also I can't use a Taxonomy view because it's impossible to pass the nodereferrer argument using this view.

Surely it's possible to return a list of all terms, without dupes, found on nodes that refer to a given node??

Comments

apmsooner’s picture

Sounds like you want to setup your view with an argument of taxonomy term and thus Action to take if argument is not present: Summary, sorted ascending and you can choose whether or not you want to display record count. This will show you the result of showing you single taxonomy terms evident among all your nodes without showing all your nodes. If you then click on the term, it would show all nodes associated with that term. Does that help?

tpainton’s picture

Hmm. let me think about that.. I wrote a response but I misunderstood what you were saying.. I'll let you know if that works. Thanks for your time!

tpainton’s picture

holy mamba. That works! Not sure why.. Thank you so much. Need to figure out the logic on this one.

tpainton’s picture

okay I get it now. The summary is displayed and it automagically reduces duplicates.. New Problem now however, I wanted a field displayed so I could display it as a link with custom url. This link would then take me to a view of all nodes that held that taxonomy term that referred to Node A. Since it is a summary view, I can't add a custom link.. sigh.

apmsooner’s picture

I think what you can do is create custom links with the url of the path produced from those summary links. So if term "sample" returns data all pertaining to "sample" when clicking on it, copy that url of the results and paste it into a custom link called whatever you want to call it. Does that make sense? I think that would solve your problem.

tpainton’s picture

The summary view overrides the field. The summary view unfortunately doesn't give you the 'Output this field as a link' option. :( If it did, I would be home free. Or did I not understand you original suggestion?

apmsooner’s picture

let me test it out to make sure it works as the way I'm thinking and I'll post back.

apmsooner’s picture

Okay assuming i'm understanding what you're trying to do... here is what i suggest:

So you created the view with the argument showing summary page of your taxonomy terms.

Let's say you created your path as http://www.yourwebsite.com/example

On that page you see your summary of terms listed like:

term1
term2
term3

When you click on each term, look at the url changing to:
http://www.yourwebsite.com/example/term1
http://www.yourwebsite.com/example/term2
http://www.yourwebsite.com/example/term3

You don't need to operate from this page as long as the argument stays within the view. So, on any page, just create your custom words with the hyperlinks pointing to each of those urls. e.g. My custom word

Does that make sense and accomplish what you are after?

apmsooner’s picture

By the way, for clarity... the "My custom word" link i just created goes to the relative path within drupal.org. When you do it on your site it will be a relative path to your domain. You can attach this link to a graphic, button, etc... I really hope that it was you were trying to accomplish and was able to help you. Good luck :)

tpainton’s picture

First off, thanks a ton for taking time to help me out. You inspired me to go answer some other peoples questions on things I knew about.

The problem is that I don't want to return all nodes associated with the term. Only nodes with the term that refer to Node A.

My Setup:
I have Node A which is referenced by lots of other nodes that have taxonomy terms from a single vocabulary. Presently, my task is to list all taxonomy terms attached to nodes that refer to Node A. Here is my current setup.

Node View
Display: Block
Argument: Nodereferrer by node (only show nodes that refer to Node A) The argument (nid) is passed by url.
Field : Taxonomy: All Terms.
Output is custom link with url 'page/node A nid/taxonomy term tid' (my_other_view/%1/%2) This takes us to a view which has arguments 1) Nodes that refer to this nid and 2)Taxonomy term. And will then display a list of nodes with the taxonomy term we clicked on that point to Node A.

It all works except for one problem.. The view displays duplicates. The reason is obvious.. I have lots of nodes that point to Node A that have the same Taxonomy term.

That led me to change the view to provide Taxonomy:Term as an argument and then just print the 'Summarize, Ascending' output to avoid duplicates.. This worked but now I can't modify the terms with 'Output this field as a link' in order to pass arguments to the view that will pull up nodes that refer to Node A. With the example/term 1 link, I will get ALL NODES that have the taxonomy term. This, I believe is what your suggestion will also do?

Sorry, if I didn't clarify better in my original post. It's a cunundrum.

apmsooner’s picture

Maybe you can figure out a way to add more arguments to filter down even further and you can put %1,%2,%3 etc.. in each arg title to specify which one happens first. I'm sure you'll figure out something anyway, i think you're at least on the right path and I'm more than happy to help out if you have more questions.

tpainton’s picture

I just had an epiphany.

Solution.

Node A has nodes that refer to it (Node B's).

Instead of asigning a taxonomy term to the Node B's. I will add a new node type that Node B references called Node C.

Node C has a taxonomy field that includes the original vocabulary.

So, instead of assigning taxonomy terms to Node B.. I have a node reference to Node C. Node C will use Unique Field Module (http://drupal.org/project/unique_field) to ensure that only one Node C with that taxonomy field exists. In addition, I'll make sure that the combination of nodereferrer field AND taxonomy term are unique so in essence, all of the Node B's will only have one reference to the taxonomy term via Node C.

Now, in order to list all taxonomy terms linked (through node C) to nodes that refer to Node A, All I have to do is create a list of nodes that link to Node A (with nodereferrer field) and include a relationship to Node C, then display out through the taxonomy field found on Node C!

The result will automatically have no duplicates, due to the many to one relationship among Node B's and one Node C. I can then also easily create a list of all Node B's that point to the taxonomy term on Node C, using nodereferrer argument.

It should also make things easier for end user because I can limit the selection of a taxonomy term to Node C's using a custom list of Node C's and if the taxonomy term isn't listed, they can then create it by creating a new Node C. Node C can also include more data that regards the taxonomy term. This is something I had not even thought of.

It's a good day. Thanks again for all your help. The drupal community is amazing. It's also inspired me to look for topics when I can that I can possibly help others.

apmsooner’s picture

Good for you. Glad it worked out for you.

voodootea’s picture

Hi, I know this post is over a year old but its the only place i've found that even remotely helps with my problem!

I have a number of nodes with one or more taxonomy terms. I only want to create a block view of all the terms which are related to a node i.e. not 'empty'.

Should be simple?!

Well, I'm constantly getting duplicated terms, even with distinct=yes, so following the advice above i've made the following view:

fields: Taxonomy: All terms
filters: node published=yes, node type=event
arguments: Taxonomy:term, Action to take if argument is not present:summary ascending, summary style:list, display:record count:yes

Ok great, it all works perfectly and returns the right stuff, no duplicates at all. The problem is when i preview the view on my page as a block, all the links are blank i.e the link is anchored with a A tag but they all only point to root like/

On the views page, i notice that when mouse over the list of terms, the urls are not standard as one would expect, they are like:

http://www.domain.com/admin/build/views/nojs/preview/category_list_2/default/TermName

instead of:

http://www.domain.com/events/categories/TermName

* BTW, ive aliased all my toxonomy paths from the start, however, the views result is not even the typical drupal format like: http://www.domain.com/taxonomy/term/TermID

I really hope you guys can help, as i've been battling with this for days, i dont really want have to use the 'taxonomy menu' module as i cant filter it or use arguments in any way..

There must be a solution out there??

Thanks in advance!

voodootea’s picture

ok, a found a solution a few days later:

http://drupal.org/node/770782

except on 1. i created a node view (as term view as suggested didnt work for me)

1) create a new Term View (not a Node View like most people tend to use and like the previous method below)
2) add the Taxonomy Term to the list of Fields
3) Add a relationship "Taxonomy: Node" and make it obligatory
4) Add some filters to narrow the results as needed. (i.e. only nodes from a certain content type)