Not sure this is a bug or by design, but is not working as I would expect.

Description of issue:

- defined two taxonomies, voc1 with terms v1t1, v1t2 and v1t3 (say they have taxonomy term IDs 11, 12 and 13 respectively), and voc2 with terms v2t1, v2t2 and v2t3 (say these have IDs 21, 22 and 23 respectively).

- creating a page view where I am filtering as following:
- taxonomy terms for v1 "is one of" v1t1,v1t2
AND
- taxonomy terms for v2 "is one of" v2t1,v2t2
- am adding an argument taxonomy term name "sorted as view"
- saved the view as "myview"

When I am loading url http://mysite.net/myview, I can see terms displayed as expected (summarised with totals by voc1). When I click on each of them, or provide them as arguments (say, http://mysite.net/myview/v1t1), again it works as expected, displaying a list with nodes tagged with any of v2t1 or v2t2 from second vocabulary.

Now, what I wanted to do is to add a second argument (also as taxonomy term name!) to further refining by second term and only get the nodes tagged by that particular term. Basically, I want to use views to get nodes that I would display when accessing say, http://mysite.net/taxonomy/term/11,22 BUT using views interface AND term NAMES instead term IDs (11 is the ID for v1t1 and 22 is the ID for v2t2).

What happens in views, is that as soon as I add the second argument as "taxonomy term name" like the first argument, then try to access a path like http://mysite.net/myview/v1t1/v2t2 I only got a blank page. I of course double checked and first tried to access http://mysite.net/taxonomy/term/11,22 which returns nodes as expected.

HOWEVER, if I replace second argument with "taxonomy term ID" instead "taxonomy term name", then use a mixed path like http://mysite.net/myview/v1t1/22 (again where 22 is the ID of taxonomy term v2t2), this time it displays correctly... (?!?!)

So my question is: is there possible to use views as described above with BOTH arguments as names, instead this mixed path (first arg as name and second one as ID)?

Am new to views and I was first reading the views docs, but found nothing to help in my particular case. I really appreciate any suggestion to help me move on.

Thank you.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

This makes my head spin. =)

Views has some long-standing problems combining different taxonomy filters, so unfortunately what you want to do isn't going to work all that well until I come up with a better solution for all of the possible taxonomy combinations.

marcoBauli’s picture

+1

same need for me. I tried same "mixed" solution (http://mysite.net/myview/v1t1/22), but it's problematic.

Advantages of using two taxonomy term names instead of a mix of a taxonomy term name and one ID are:

  • use of only one arg type (Term name)
  • node URL is more SEO friendly, displaying exactly the right terms in it, and not any nid numbers.

cheers

merlinofchaos’s picture

I realize this is a big want, but it's also hard, so don't expect this to work better any time soon.

marcoBauli’s picture

Version: 5.x-1.6-beta5 » 4.7.x-1.x-dev
Category: feature » support

Thanks for precising Merlin.

Views module is just *great* as it is, these are only some small refinings to a piece of genius :)

mvc’s picture

This feature would be a very welcome addition to Views. In the meantime, I've been able to get something similar working via custom argument handling code (details here).

Michelle’s picture

Version: 4.7.x-1.x-dev » 5.x-1.6-beta5
Category: support » feature

I want to chime in for requesting this and bumped the version up. Just ran into this and couldn't figure out why it wasn't working until I found this issue. If this could somehow be made to work, that would be awesome.

Michelle

Leeteq’s picture

+1 and subscribing

Summit’s picture

Hi,

+1 to get this working!
The solution with the argument handling code is not working for me. I don't know why.
The views and panels modules are great, with this feature working it would be able to build a panel using views with more than one taxonomy term as a argument.

greetings,
Martijn

nath’s picture

This is something we need for our site as well.

thelizardking’s picture

Version: 5.x-1.6 » 5.x-1.6-beta5
Component: Views Data » User interface
Category: support » feature

I was working with views and was trying to incorporate two taxonomies in a view. I am basically embedding two views in the main view. The two views are to be sorted on a different taxonomy. I am using argument and filter. The content is organized based on products and models and FAQs are further organized based on sub FAQ types. I need to sort depending upon the products, models as well as FAQ issues.
I am going to create my own script to make my solution work and later look on this issue and try to fix the problem. If anyone has a solution or is working on one, please respond and I can contribute to the solution rather than working from scratch.

thelizardking’s picture

I used CCK fields to create sub-topics and used filter based on this field.

Caleb G2’s picture

subscribing. Glad to find out that I wasn't going nuts at least...

coupet’s picture

subscribing. good feature to have.
further details on concept and implementation challenges would be welcomed.

alanic’s picture

Version: 4.7.x-1.x-dev » 5.x-1.6-beta5
Category: support » feature

I'm working on this right now. I thought I'd share what I have.

Here is the query generated for one term name argument.

SELECT node.nid, node.sticky AS node_sticky, node.created AS node_created_created 
FROM node node 
LEFT JOIN term_node term_node ON node.nid = term_node.nid 
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid 
WHERE (node.promote = '1') AND (node.status = '1') AND (term_data.name = 'term1') 
ORDER BY node_sticky DESC, node_created_created DESC

Here is the query generated for two term name arguments.

SELECT node.nid, node.sticky AS node_sticky, node.created AS node_created_created 
FROM node node 
LEFT JOIN term_node term_node ON node.nid = term_node.nid 
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid 
LEFT JOIN term_data term_data2 ON term_node.tid = term_data2.tid 
WHERE (node.promote = '1') AND (node.status = '1') AND (term_data.name = 'term1') AND (term_data.name = 'term2') 
ORDER BY node_sticky DESC, node_created_created DESC

At first glance, one obvious correction is "term_data2.name = 'term2'", but of course this does not solve it since both term names are mapped to the same term_node.tid. Here is the fixed query:

SELECT node.nid, node.sticky AS node_sticky, node.created AS node_created_created 
FROM node node 
LEFT JOIN term_node term_node ON node.nid = term_node.nid 
LEFT JOIN term_node term_node2 ON node.nid = term_node2.nid 
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid 
LEFT JOIN term_data term_data2 ON term_node2.tid = term_data2.tid 
WHERE (node.promote = '1') AND (node.status = '1') AND (term_data.name = 'term1') AND (term_data2.name = 'term2') 
ORDER BY node_sticky DESC, node_created_created DESC

Since there are term_node.tid and term_node2.tid, we can really enforce two terms.

So, if we can make the module create this SQL, this should be fixed. I'll see what I can do.

Btw, shouldn't this be a bug report instead of a feature request?

alanic’s picture

FileSize
1.04 KB

Ok here is the patch, to be applied to the current release (views-5.x-1.6). Works for two taxonomy term name arguments, no reason it shouldn't work for more.

I hope this helps all the people subscribed here! :) Let me know of any issues.

alanic’s picture

Category: feature » bug
Status: Active » Needs review

Forgot to change status to patch. Also making it a bug report.

alanic’s picture

Here is another patch that will fix the summary generation. Right now when there are more than one arguments, not all but at least one argument is provided, and summary is selected for default action, the output is blank. This fixes that to be how it should be: links of possible terms that the current filtered group of nodes have. You will, however, see the currently selected terms in that list. This is a result of the ambiguity of having two term arguments. If they were restricted to vocabularies it wouldn't be ambiguous. Which I also have implemented and I'm planning to provide it once it looks better, let me know if you need the current code for it.

This patch should be able to be applied before or after the other patch I posted.

Summit’s picture

Hi,

I will try your patch.
Is this patch also to use arguments on the filters?
Right now I can only set the filters manually related to taxonomy terms. That's why I am asking this.
I will give you feedback on the patch later this week.

Greetings,
Martijn

merlinofchaos’s picture

The reason that I've never committed a patch that does this is because this version will break the interaction when you add the taxonomy term field to the view.

Summit’s picture

Hi Earl,

So what to do? There is a argument handling code which says to help to support multiple term names input as arguments: http://drupal.org/node/54455#comment-239583

I tried it and it worked for views, but panels 2 doesn't like it yet. See http://drupal.org/node/192624 for my bugreport for this specific argument handling code and my view which will not save in Panels 2 (hopefully not something stupid on my side...).

Will this be the short term solution to use? Instead of the patch in this thread?

Greetings,
Martijn

alanic’s picture

Re: Martijnhaan
Thanks for considering the patches. I didn't do anything about filters. In fact I'm not sure I understand what needs to be done about filters. What does "using arguments on filters" mean? I'm probably missing the point because I didn't use filters that much. All I know is that filters on taxonomy names can be set manually by the admin, or when they are exposed they can be modified by the user. I'd appreciate if you could tell me the scenario you are referring to.

Re: merlinofchaos
What do you mean "break the interaction"? Again I'm missing the point and would love some explanation.

On the quest to understand what I'm missing, I created two term name arguments and two term name filters, and they all seemed to work fine together. I exposed one of the filters and it was still fine. It wouldn't let me expose the other filter anymore but I don't think that's what you mean.

merlinofchaos’s picture

The easiest way to is for you to see it; use this patch, create the filters + the arguments, and then enable the taxonomy term field (that doesn't show multiple terms). Be sure to use this on a system where nodes have multiple terms.

alanic’s picture

I just did that and it works perfectly. Since you didn't provide enough detail I'll provide more to make sure I did what you called for:

* In views UI I created a copy of frontpage,
* removed the default "Node: Feed Selector" argument
* added two "Taxonomy: Term Name" arguments
* didn't touch the two default filters "Node: Published" and "Node: Front Page"
* added two "Taxonomy: Term" filters with "Is all of" and selected a single term for each filter that is different from the other
* went to the url, since arguments were not provided I got summary links
* I clicked on them to provide two arguments, I chose ones that are different than the ones I chose for filters
* The page had two arguments in the url and it displayed three nodes from the database that had all four terms (two terms from the arguments, two terms from filters)
* There are many other nodes in the database that satisfy subsets of those four but none of them showed up as expected

So, as I said it worked perfectly. I'm doing this on a temporary installation so if you want to take a look I can give you the URL and the admin password. Let me know if this is not the scenario you were talking about.

edit: per our irc chat today this case covers it and there is no apparent problem with multiple arguments and multple filters.

Summit’s picture

Hi,

So this is the solution right now for multiple term names as arguments?
With filters you can set depth, say 3 depth means that all nodes with a specific to choose taxonomy term AND all the nodes with more depth taxonomy terms will be shown.
Until now I can only set this manually as admin.
What I would like is that with typing in the arguments the setup filter on top level with depth and vocabulary chosen gives the wanted situation.

So an example is:
Vocabulary regional
Taxonomy term: England
Taxonomy subterm: London
Taxonomy subsubterm: Banking
Taxonomy subterm: Manchester.

With typing ins www.example.com/england/Londen

The nodes should come up from Londen with two Arguments Taxonomy Terms set.
The nodes should come up from Londen And Banking with also the Filter set to Vocabulary Regional and Is-all-off with depth 3.

Is this doable?
greetings,
Martijn

alanic’s picture

Oh I see, you want the depth option for term name arguments. There is already an option for the number of characters, and there can be only one option. I guess another argument type needs to be created for that. I think similar code from filters can be used for this purpose. Since I don't really need this I won't work on it for now, but I would be glad to help out whoever tries to do this.
I also think that this depth thing is not related to the original issue here and needs a new feature request entry.

Btw, here is the query created for the two argument and two filter case with the patch. As you can see all arguments have their distinct joints.

SELECT node.nid, node.sticky AS node_sticky, node.created 
AS node_created_created FROM {node} node 
LEFT JOIN {term_node} term_node ON node.nid = term_node.nid 
LEFT JOIN {term_hierarchy} term_hierarchy ON term_node.tid = term_hierarchy.tid 
LEFT JOIN {term_node} term_node2 ON node.nid = term_node2.nid 
LEFT JOIN {term_hierarchy} term_hierarchy2 ON term_node2.tid = term_hierarchy2.tid 
LEFT JOIN {term_node} term_node3 ON node.nid = term_node3.nid 
LEFT JOIN {term_data} term_data ON term_node3.tid = term_data.tid 
LEFT JOIN {term_node} term_node4 ON node.nid = term_node4.nid 
LEFT JOIN {term_data} term_data2 ON term_node4.tid = term_data2.tid 
WHERE (node.promote = '1') AND (node.status = '1') AND (term_node.tid = '17') AND (term_node2.tid = '18') AND (term_data.name = 't3') AND (term_data2.name = 't6') 
ORDER BY node_sticky DESC, node_created_created DESC;

Maybe a fix for filters in order when there is no depth argument. The node_hierarchy joins seem unnecessary.

Summit’s picture

Hi,

I installed the patch, and it is giving the following errors:

warning: Invalid argument supplied for foreach() in /home/public_html/modules/taxonomy_hide/taxonomy_hide.module on line 104. 
warning: Invalid argument supplied for foreach() in /home/public_html/modules/taxonomy/taxonomy.module on line 32

It is completely not working on my argument handling code for filter (blank page). I just don't get it right... see: http://drupal.org/node/163912#comment-637432

How can I use the argument handling code for two terms to be able to show then:
1- all nodes which have those terms as tags, and because of a filter with depth 3;
2- also show the terms "under" these tags?
(May be I need to set a different issue for this, if so sorry to fuzz about it on this thread).

But what I want is that because of using the terms as arguments the nodes ars shown with both terms tagged (your patched solution, great!) AND the nodes with the two terms as filter with depth 3, so all terms underneath the both terms are shown.

For example the url www.example.com/schools/england/london
Should show all tagged nodes with england AND london Your solution, right?
And show the nodes tagged with all nodes with are "under" london situated because of using a depth of 3. => on this argument I would like to set the argument handling code for the filter.

Greetings,
Martijn

alanic’s picture

My patches only change views_taxonomy.inc in the views module, so I'm not sure if those warning messages are related to my code at all.

As far as I know, "depth" option is only in filters. Filters and arguments are ANDed together. Therefore you can't have what you explained there.

Yes it should show all nodes that have england AND london tags, but this means that you can't have any node that does not have england and london together. No tags "under" london will be shown if the node does not have the tag "london". That's how arguments and filters work.

Of course if someone adds the "depth" option to arguments what you said could be possible.

If you think there is a specific case that term name arguments are not working well with filters I would be glad to look at it. But don't forget that they have to be AND'ed. So, you can only have tags "under" certain term using filters. Once you put the term name in the argument, you can't have terms "under" a term anymore.

Summit’s picture

Hi,

Thanks for your explanation!
I get the filters behaviour to make a view for every filter I need. But this way I will have a lot of views with only the filters altered every time.

The Filter functionality works as described. If I Filter a vocabulary on a top-lever taxonomy term with depth 3, the Nodes with this taxonomy term AND the nodes with taxonomy terms UNDER this term (so the subterms themselve are not in the url/arguments) are shown.

This manually to add functionality I would very much like to have automated. So with one view I can build all my wanted view-output, only by using the same arguments! If you know the argument handling code to get this done, it would be great!

Thanks for your patch and explanation!

Edit:
I tried a different approach to get my filter available (My vocabulary = 109):

if (isset($args[0])) {
views_view_add_filter($view, 'term_node_109', 'tid',  'AND', $args[0], '3');
views_sanitize_view($view);
}
return $args;

Now I got errors in my views_taxonomy.inc, with the patch:

warning: array_map() [function.array-map]: Argument #2 should be an array in /home/public_html/modules/views/modules/views_taxonomy.inc on line 502. 
warning: Invalid argument supplied for foreach() in /home/public_html/modules/views/modules/views_taxonomy.inc on line 533

What do I do wrong, is the argument handling code incorrect?
May be it has to do with the patch, thats why I post the comment here.
Thanks for getting into this!

Greetings,
Martijn

Summit’s picture

Hi,

I think the error was in my argument handling code.
It is still not working, but I think I am getting close. This is my argument handling code now:

if (isset($args[0])) {
$filter_arg0 .= _taxonomy_get_tid_from_term($args[0]);         <= I need the tid to get the filter working, right?
views_view_add_filter($view, 'term_node_109', 'tid',  'AND',array(0 => $filter_arg0 ), '3');    <= I need to use array with the tid, right?
views_sanitize_view($view);
}
return $args;

What I want is that the url www.example.com/view_url/foo/bar the foo (arg(0)) is used as filter-value. Foo is a taxonomy term in the vocabulary 109. I am trying this now with the above code, but it still isn't doing what I want, namely filter on the taxonomy term foo :( so that all nodes with foo,
Please help. I am allmost out of options now how to get this done..

Greetings,
Martijn

Summit’s picture

Hi,

Will these patches go in: http://drupal.org/node/77543#comment-633801 / http://drupal.org/node/77543#comment-634685
I will put it in production after these go in off course.
Until now no errors because of the patches as feedback to Alanic :)

greetings,
Martijn

Summit’s picture

Hi,

It looks that, thanks too Dmitry, I have a argument handling code, which works for two taxonomy terms now, without patching views as discribed above!!
What it does is that it filters the content to the first argument code and its subterms, and uses the second argument code to keep within the scope of this. So for example in my site: http://www.gratis-informatie.nl/over/wintersport/frankrijk will give all information related to wintersport (and all subterms) within frankrijk (france in dutch :)

I use the following argument handling code:

$tmpterms = taxonomy_get_term_by_name(arg(1));
$view->filter[0][value][0] = $tmpterms[0]->tid;
$tmpterms = taxonomy_get_term_by_name(arg(2));
$view->filter[0][value][1] = $tmpterms[0]->tid;
$view->filter[0][options] = 3; // if you always use depth=3 for all cases you can just place it manually once (in options field) and delete this line
return $args;

Could someone please comment on this. Is it true that the patch is not necessary any more, or do I see something wrong?
Does the patch do more, other things that I am not aware of?

Thanks in advance,
Greetings,
Martijn

alanic’s picture

As far as I can tell, that argument handling code is using the terms selected in arguments to change filters in runtime. Which is maybe not the most efficient way to do it because you probably will have two extra joins in SQL, but I guess it's fine. I didn't try it, but in fact I'm a little surprised to hear that this works because I expect the arguments and filters to be ANDed, but if it works that's fine.
The patch is functionally equivalent to it except it doesn't require those filters (probably 2 less joins), supports correct summary generation when arguments are not all filled in, but has no depth option.

Summit’s picture

Hi Alanic,

Thanks for your remarks on my code. And the depth is exactly what I needed. So without depth I would use your patch. And Yes the depth is working!
But if you could patch that also the depth is working..than your patch would be what I will use!

Greetings,
Martijn

Summit’s picture

Hi Alanic,

I tried your patch and my own argument handling code. It get stuck by terms, where you put a "-" between to words.
Like the term: alpe-dhuez in my situation.

Did you get your system working with 2 arguments and a "-" between words for one term? Or do you also have this?
Thanks in advance for your reply!

Greetings,
Martijn

alanic’s picture

Term names with dashes work for me.

jefbak2’s picture

Version: 5.x-1.6-beta5 » 5.x-1.6
Component: User interface » Views Data
Category: bug » support
Status: Needs review » Active

It is really hard to figure out where to post on this issue but I just setup a whole taxonomy to use cck taxonomy fields and views to dispay and sort by Client Name. I don't have an option to sort of course.

So if I setup a text field in CCK instead I could sort on it?

jeff h’s picture

I don't know why you say "of course" :) It seems to me logical that, since taxonomy terms have weights and thus have an order, that you should be able to sort a view's output based on a taxonomy vocab.

But yes, if you put a CCK dropdown in your content type, I do believe you will be able to sort your views result on this.

gravit’s picture

Version: 5.x-1.6-beta5 » 5.x-1.6
Component: User interface » Views Data
Category: feature » support

Merlin - would the following be a possible option?

Currently the views module allows filters by not just term name, but a term name in a specific vocabulary.

However, for arguments, there is only the generic option for "taxonomy: term name".

How difficult would it be to add in the ability to have taxonomy arguments specific to a vocabulary - just like the filters. Or to ignore certain vocabularies in the arguments - And would this solve the problem? It seems that it would in my particular case where I want to filter by one vocabulary, but customize the view url by another.

catch’s picture

Component: Views Data » Code
Category: support » bug
Status: Active » Needs review
jefbak2’s picture

I guess the ways to sort are unclear for me sometimes.

I setup a view only to find that my vocab term does not show up but is generalized for the sort criteria.

I need to sort on an arbitrary report date field (not the publish date of the node) which I am using the calendar module for, and on Report type which can be a taxonomy field or a taxonomy term in the views Fields section. The field version has sort functions, but the taxonomy term does not.

In views Sort Criteria I also have the choice of using a generic taxonomy term with no specifiable term or I can choose the taxonomy field version which does include the report type.

This can get confusing for me very quickly as you can tell.

When should I set sorting in Fields and when should I use Sort Criteria instead? Using both seems to be problematic for me.

In views I need to be able to make the sort flexible so that that the view can default to Report Type and then Newest date first.

catch’s picture

jefbak2, please open a new issue for this support request, this one is long enough as it is, and has nothing to do with sorting.

jefbak2’s picture

Sorry Catch, these issues can seem very similar to me. Not black and white.
I will repost.

fumanchu182’s picture

For our purposes I wrote an argument handler for the specific view. It is a quick way of finding the taxonomy term associated with the taxonomy id (tid). It is as follows:

// we are processing each taxonmy term and turning it into a taxonomy id to be returned in an array
// taxonomy terms are seperated by "/" example: mediaview/New York/Career/Health/Style

// returns a tid of the current term
function get_taxonomy_id_by_term($term)
{
     $result = db_query("select tid from term_data where name ='%s';", $term);
     $row = db_fetch_array($result);
     return $row['tid'];
}

//debug -> drupal_set_message(print_r($args, true), 'error');
foreach($args as $key=>$arg)
{
     // since there is no get_taxonomy_id_by_term function lets write one
     $args[$key] = get_taxonomy_id_by_term($arg);
}

//debug -> drupal_set_message(print_r($args, true), 'error');
$args = array(implode(" ",$args));
//debug -> drupal_set_message(print_r($args, true), 'error');
return $args;

One other aspect of the view we are going to change is the way the SQL is logically OR'ed together. We would like it all to be logically AND'ed. I have been poking around in views_query.inc but is this the right file to be poking around in (have only given it a brief glance and haven't changed any code yet). Also what would be the game plan to create this logical functionality without breaking other views ability to logically OR terms/term ids together?

-A

patchak’s picture

hey there Alanic, does this patch allows to use two term names as arguments on a single view?? How can I set it up ?? Do I need to add two times the "Taxonomy/term" argument, or I need to add it only once in the view's setup??

This is pretty interesting feature btw, will try and review the patch tonight.
Patchak

alanic’s picture

Yes, my patch allows you to add two of those and makes them work as expected. No you shouldn't add one if you want two. I'm on holiday right now, so I can't comment more in detail before 15 days. HTH.

dugh’s picture

Status: Needs review » Reviewed & tested by the community
Summit’s picture

I do not think you need this patch to get this working.
I didn't use this patch, only smart working argument handling code...Views is such a great system, thanks to the good great mity MerlinofChaos!

Look at www.vindtocht.nl/over/kerst/nederland and www.vindtocht.nl/over/kerst/europa.
The terms you type in after the view "over" shows the resulting view-output.

But of course ok when it works also with a patch, but I like the flexibility of normal views update.
As long as this patch is not committed I will use the argument handling code.

Could it be that may be my method is more cpu-using? I don't know.
Open for discussion about this.
Enjoy your holidays!

greetings,
Martijn

daniel.hunt’s picture

I'm interested in this too - subscribing

Misange’s picture

Could you please summarize what you did in views, what code you wrote and where ? I am trying to do exactly what you describe (however in views2 and drupal 6.6) but fail. This thread is very long and somewhat confusing for someone discovering Drupal.
Thanks for sharing
Misange

alanic’s picture

It's been a long time since I did this and I'm not willing to work on it right now. But you can download the version I used and look at the patch files to see what I've changed. Patch files are the exact answer to the question "Could you please summarize what you did in views, what code you wrote and where?". Just open it with a text editor and take a look, they have line numbers and line change information. The lines starting with - are the ones that are removed and the lines starting with + are placed instead. Other lines are there to give sense of context.

merlinofchaos’s picture

Threads for Views 1 won't help you at all for Views 2; they're basically different pieces of software.

esmerel’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

At this time, only security fixes will be made to the 5.x version of Views.