Views Contextual filter and manual Pane argument

Last updated on
1 December 2016

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

I wrote this down because it took me a long time to find a solution to do the following:

What?

I have a views pane that lists titles and an image plus a teaser text. To make it reusable for nodepages/panels and taxonomy pages i exposed the "contenttype" as a pane setting and added three contextual filters

  1. nid: to exclude the node itself if the pane is shown on a node page
  2. manually nid input: a field on the pane config itself where i can input nodes like 1+3+44 that will be loaded then
  3. has taxonomy term: because i also wanted to be able to use that pane on taxonomy/term/% pages

Views pane argument settings
views_pane_settings.png

Views arguments
view

As said the second argument is a manual input on a panel config. See the field that has node ids like 247+248+249.
pane settings

Taxonomy page

I enabled the shipped taxonomy panels template and used it for my taxonomy pages.

The problem

The problem was that the pane did not work on my taxonomy pages. Taxonomy is the last argument. Of yourse only some panes actually use this manual node id field and if it is not present the argument filter value will be null and the taxonomy filter is never used.
You can chose "Display all results for the specified field" on the "manual nid" filter but that will not work, so you need to check "provide a default value" and enter "all". Basically that filter will not alter the query then.

Example

WORKS: If i input the arguments in the views preview "248/249+247/all" the result will be:

SELECT node.nid AS nid, node.title AS node_title, node.created AS node_created, node.sticky AS node_sticky, 'node' AS field_data_field_image_node_entity_type, 'node' AS field_data_field_product_image_node_entity_type, 'node' AS field_data_field_news_bild_node_entity_type, 'node' AS field_data_body_node_entity_type FROM {node} node WHERE (( (node.nid != '248' OR node.nid IS NULL) AND (node.nid IN('249', '247') ) )AND(( (node.status = '1') AND (node.type IN ('article')) ))) ORDER BY node_created DESC, node_sticky DESC LIMIT 4 OFFSET 0

with the 3rd argument beeing all it will not add a WHERE taxonomy_index.tid = ... to the query and basically skip this filter.

DOESNT WORK: If i input the arguments in the views preview "248/249+247/null" the result will be:

SELECT node.nid AS nid, node.title AS node_title, node.created AS node_created, node.sticky AS node_sticky, 'node' AS field_data_field_image_node_entity_type, 'node' AS field_data_field_product_image_node_entity_type, 'node' AS field_data_field_news_bild_node_entity_type, 'node' AS field_data_body_node_entity_type FROM {node} node INNER JOIN {taxonomy_index} taxonomy_index ON node.nid = taxonomy_index.nid WHERE (( (node.nid != '248' OR node.nid IS NULL) AND (node.nid IN('249', '247') ) AND (taxonomy_index.tid = 'null') )AND(( (node.status = '1') AND (node.type IN ('article')) ))) ORDER BY node_created DESC, node_sticky DESC LIMIT 4 OFFSET 0

as you now see it does "AND (taxonomy_index.tid = 'null') )" and of course that fails.

Help improve this page

Page status: No known problems

You can: