I have a view of several fields from one content type (content type is called "summary"). A required field in the content type is a term reference, called "connector". "connector" is also a required field in a different content type ("details"). I only want to include the content of a node summary in the view if a node details exists with the same "connector" reference.

Is this possible when using views? Using the interface would be ideal, but since I am already doing some post-rendering for that view, it might be easiest to remove the unwanted entries there?

From what it sounds like, it should be possible to do this using the relation module. However, I can't wrap my head about how to configure it.

Any help highly appreciated!


After sifting through several modules, I decided that it's easiest to achieve this with theme pre-processing. Here is what I did:

I used the drupal 7 schema that I created years ago (http://upsitesweb.com/blog/2011/06/drupal-7-database-schema), to figure out which tables to join. The vocabulary I am using has the vid 14. I pre-processed the view and checked for each line, whether the corresponding node in the details content type exists, rewrite the view entries to only contain matched entries.

It must be possible to also achieve the same with contributed modules. However, it was faster and more efficient to use views pre-rendering instead, especially, since other aspects of this view are getting pre-rendered anyway.

function theme_views_pre_render(&$view) {
   if ($view->name == "summary_details") { //filtering summary entries without detail
      $nids = array(); // array of nodes 
      $nodeswithdetails = array(); // manipulated results
      foreach($view->result as $key => $result) // check each node of the result array on it's nid
        $nid = $result->nid;
        $return = theme_ensure_details($nid);
        if ($return == 1) {
           $nodeswithdetails[] = $view->result[$key];
      $view->result = $nodeswithdetails; 

function theme_ensure_details($nid) {

   $results = db_query('SELECT s.nid AS sum_nid FROM {node} n, {node} s, '
                      .' {taxonomy_index} t, {taxonomy_index} t1, '
                      .' {taxonomy_term_data} td WHERE t.tid=t1.tid '
                      .' AND t.tid=td.tid AND td.vid=14 AND n.type=:dettype '
                      .' AND n.nid=t.nid and s.type=:sumtype AND s.nid=t1.nid '
                      .' AND s.nid= :nid',
         array(':nid' => $nid,':revtype' => 'details', ':reptype' => 'summary'));

    $found = 0;
    foreach ($results as $row) {
       if ($row->sum_nid == $nid) {
       $found= 1;
  return $found;

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.