This is a Views 6.x-2.x problem: On a site with many different views (many of which are blocks included in Panels that pass arguments to blocks) I would like to filter views by a taxonomy term depending on the domain the site is visited through. This filtering should be additional to a first argument (taxonomy term).
The site is configured to work with different domains, let's say example1.com and example2.com. I want to "connect" those domains to the taxonomy terms 45 and 115.
So for example:
example1.com/my_view/1 Should show all nodes that have term 1 and term 45.
example2.com/my_view/1 Should show all nodes that have term 1 and term 115.
My approach was to add a second argument (the first is the default taxonomy term ID argument). As default argument I use the following snipped in the argument handling code:
<?php
// Get domain.
$host = preg_match('/[^.]+\.[^.]+$/', $_SERVER['HTTP_HOST'], $hit);
$host = $hit[0];
// Select taxonomy term.
if ($host == 'example1.com'){
$taxonomy = '45';
} elseif ($host == 'example2.com'){
$taxonomy = '115';
}
return $taxonomy;
?>
This works when I use a page display with the path my_view/% (making only the first argument mandatory). But when I use it in a panel, I just get an empty view (if "no context" is chosen) or the second argument doesn't have any effect (if "term id of first/all term" is chosen).
Any ideas what could be wrong? I have really tried a lot.
As I found out here, views ignores the second argument if the first is not present. So setting the following default argument for the first taxonomy argument solves the problem, although it's more of a workaround than a real solution:
if (arg(0) != 'taxonomy') {
return 'all';
} else {
return arg(2);
}