I have two content types, one I'll call "best practices" and one "funding sources". Both types of content have three separate taxonomies that apply to them, with multiple terms in each. I've created a view with exposed filters that let's users search for "best practices" based on taxonomy terms. This works great. The next step is trickier, and what I need help with.
I've created a block in Views that shows up on each "best practice" full node view that lists all the "funding sources" node titles. Using Views arguments, I want to filter the results in the block by two of the vocabularies. I've seen a lot of code and modules for simple related content, but nothing that deals with this multiple taxonomy, multiple terms issue.
Here is an example: a "best practice" node type has the three vocabularies "area", "user" and "benefit". If a "funding source" node has at least the same terms in vocabularies "area" and "user", I want it to show up in the block. However, I don't want to have to match the terms in those two vocabularies exactly. So if the best practice has the term "rural" in vocab "area", I want all the "funding sources" that have the term "rural" (but not ONLY the term "rural") to display.
I've found many snippets of code out their to use in the Views arguments, but none seem to work when I validate the argument with taxonomy term and select the vocabularies. I assume this is the method I should use, I just need the right code (which I don't know how to write). Of course, maybe this assumption is incorrect...
Any help would be appreciated.
Comments
You need to learn how to use
You need to learn how to use view arguments.
Make a view with a block display that list content of type 'funding sources' in the format you want.
Add an argument on type Taxonomy: Term Id
Set 'Action to take if argument is not present' to 'Provide default argument'
Set 'Default argument type' to 'PHP Code'
For code use
You will need to change 'best_practices' to the actual content type.
Set 'Validator' to 'Taxonomy Term', select appropriate vocabularies.
Set 'Argument type' to 'Term IDs separated by , or +'
Check 'Allow multiple terms per argument'
Check 'Reduce duplicates'
Save/Update argument
Save/Update view
Thanks nevets, this is where
Thanks nevets, this is where my knowledge gets fuzzy, I haven't educated myself about views arguments yet. I've followed your instructions, but drupal returns a big error in red on every page:
warning: Invalid argument supplied for foreach() in /home/slotte5/public_html/drupal/includes/common.inc on line 1647.
Also, I assume that allowing multiple terms per argument means that the same set of terms doesn't have to be present from each vocabulary for a match but rather the "best practice" and the "funding source" only need one overlapping term from each of the selected vocabularies in order to show up in the block?
As for the error, I would
As for the error, I would start by reducing the code till you determine which line causes there error.
As for
The code assume the types are using the same vocabularies, it only matches on the same terms (the tid or taxonomy term id) to be exact.
I've "commented out" each
I've "commented out" each line, and the error persists. I'm pretty much ignorant of PHP code, so I'm no good at error-checking this. I've found some other code that seems, to work, but whenever I use Taxonomy Term for the "validator options" I run into issues. First, here is the code:
$node = node_load(arg(1));
if ($node) {
foreach($node->taxonomy as $term) {$terms[]=$term->tid; }
return implode('+',$terms);
} else {
return;
}
I select Taxonomy Term for validator options, then select one or more of my vocabularies and hit update and save. When I type in some taxonomy term IDs and hit preview, the correct node titles show up. However, on my actual node page, the block does not show up. I'm pretty sure it has to be something with the validator since if I revert to basic validation it shows up again, but this doesn't allow me to filter by vocabulary. Any thoughts? Is there any documentation on validator options, it's not clear from the text on the page what exactly it means (match all terms from that vocabulary or just one, etc).
Were you able to resolve this?
I am experiencing the same issue with the invalid argument on line 1647 of common.inc. Have checked numerous other support threads here and none of them seems to apply.
In general terms, when you
In general terms, when you use foreach, you need to make sure the variable is an array. In the case of $node->taxonomy, if a node does not have any terms, $node->taxonomy is not set.
Thanks, nevets
So does this mean that if I have a vocabulary defined, but not every node has a term for it, this could be triggering the error?
It is a possibility,
It is a possibility, particularly with code snippets.
reflecting the same node back
Hi,
I just used this code and it works great. There is only one problem: the list of nodes returned include the present node. Do you know any way to exclude the current node using this view setup?
Yes, configure the "Node:
Yes, configure the "Node: nid" argument, toward the bottom of the form is a checkbox to exclude the node from the listing.
Heres a code that works if you use tags to classify your content
sandy
i'd like to know how i make an autopopulate menu
that with that css add the terms for a Brand Vocabolary]
so when i crate a content and add a terms to Brand vocabolary
the menu automatic upgrade itself
and remind me to the correct filtered view
i've just installed taxonomy menu module
adult adhd