1

I create a view with two arguments: Taxonomy ID (tid) and Node NID (nid). I leave the default settings for tid and set a default argument for nid to a fixed value (let's say: 1). The tid argument is configured so that all values are shown in case it is not present. This should show all nodes except the one with NID 1.

BUT: This only works if the NID argument is the first argument. If it's the second argument, it is excluded from the query:

Query with nid as first argument:

SELECT node.nid AS nid
FROM node node
WHERE node.nid != 1  OR node.nid IS NULL

Query with nid as second argument:

SELECT node.nid AS nid
FROM node node

I'm wondering why that is? What I want to accomplish is actually to exclude the result of one view from another. To do that, I add nid as an argument, get the nids of a different view and tell views to exclude them. That works just fine, but only if nid is the first argument. But I need to have taxonomy as the first argument and I don't understand why that excludes my nid argument.

Although in a different context, I think I had the same problem here: https://stackoverflow.com/questions/20248929/filter-a-drupal-view-displayed-in-a-panel-by-taxonomy-term-depending-on-domain

  • For the record: This issue also appears in Views 7.x-3.8 and is handled in your Drupal issue #2273267. – tanius Aug 28 '14 at 11:57
2

It seems that views ignores the second argument in case the first argument is not present, although the first argument is configured to show all values if it is not present. Setting the following PHP code as default argument for the taxonomy term solves my problem:

if (arg(0) != 'taxonomy') {
  return 'all';
} else {
  return arg(2);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.