Let me explain the issue in detail. I have created two views. The first view displays listing of content for content type named Invoice. The View has a page display. This view is working fine.

I want when a user clicks on any content item the resulting page should use the another view which I have created to show the items for a specific content item based on the node id passed.

How to pass the node id as a contextual filter for second view. I have given the path for second view as node/%, but then the view just work for all content types. I don't want that thing to happen. I just wants to have that view called for Invoice content type items.

I have also used validation criteria for contextual filter, but that doesn't work.

  • You mean to say like the second view will render the items based on the content type of the node-id passed as a contextual filter..? OR just invoice..? Feb 6, 2014 at 7:30
  • Yes exactly the second view will accept contextual filter as a nodeid passed from first view.. Feb 6, 2014 at 7:38

1 Answer 1


A simple query alter will do the job.

Say example you are using a module my_views_invoice

    function my_views_invoice_views_query_alter(&$view, &$query) {

    $nodeid = $view->args[0][1]; // get the node id from contextual filters. Ex :Array ( [0] => node [1] => 1 )    

   $content_type =  node_load($nodeid) ;// get the content type from the node load : Ex $content_type->type

      if ($view->name == '<Your view name>') {
// Add a where condition in the query like below..

        foreach ($query->where[0]['conditions'] as $key => $conditions) {
          if ($conditions['field'] == 'node.type') {
            $query->where[0]['conditions'][$key]['type'] = $content_type->type;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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