How to exclude nodes from views result? I have a view with one field that shows rendered nodes, and a contextual filter (multiple values allowed) that provides the nids that should be used in the view.

Each node (with nid from the context filter) contains a node reference field with multiple values (nids of related products).

My problem is that a number of these related products, are in fact unpublished nodes. So how can I exclude these unpublished nodes from showing up in the views result? Just adding the filter Published = Yes does not work since the field in the view always is published. It is some of the rendered nodes, produced by that field, that in their turn are unpublished.

UPDATE: in a custom module I have now added this snippet:

function mymodule_views_post_execute(&amp;$view) {
  if ($view-&gt;name === 'my_view' &amp;&amp; $view-&gt;current_display === 'related_products') {
    foreach ($view-&gt;result as $result) {

      foreach($result-&gt;field_field_add_products as $key =&gt; $product){
        if($product['rendered']['#node']-&gt;status == 0){
          unset($result-&gt;field_field_add_products[$key]);
        }
      }
    }
  }
}


...and this does actually exclude the unwanted products. BUT they don't just leave gracefully. They leave a gap in the (repsonsive) grid that I use to show these products. How do I exclude them AND the space they occupy in my views grid?

UPDATE: this is my PHP snippet in the contextual filter:

$node = menu_get_object();
$value = null;
if(empty($node-&gt;field_lagg_till_givargrupp['und'][0]['nid'])){
    $node-&gt;field_lagg_till_givargrupp['und'][0]['nid'] = NULL;
    return FALSE;
} else {
    $groups = $node-&gt;field_lagg_till_givargrupp['und'];
    foreach($groups as $group){
        $group_nid = $group['nid']; // hämta node-id
                $value .= $group_nid.",";
    }
    return rtrim($value, ",");
}


It works well and supplies the nids wanted (the node ids for the nodes with multiple products grouped in node reference fields).

And this is a partial screenshot of the view:


I use the field Innehåll: Titel (Content: Title) to group the result by the title of each product group. The field Innehåll: Koppla givare (Content: related products) produces all the nodes present in the node reference fields. If there are 20 products entered in that multiple value field, I will have 20 rendered nodes as a result, of which some are not publised. See the resulting view below. The gaps are unpublished nodes that I succeeded in excluding with my snippet above. 



So how do I rebuild the view result so that there are no gaps?
Ok, so this was in fact very simple... though it took me a great deal of time to find the solution. I removed the snippet in the custom module above and instead I added the code below in template.php. Hope it helps somebody. I found the solution here: http://agaric.com/blogs/altering-views-results

function mytheme_views_pre_render(&amp;$view) {      
if ($view-&gt;name === 'myview' &amp;&amp; $view-&gt;current_display === 'mydisplay') {
        foreach($view-&gt;result as $index=&gt;$val){
          $product_node = node_load($val-&gt;field_data_field_related_product_nid);
          if($product_node-&gt;status === '0'){
             unset($view-&gt;result[$index]);
          }
        }
    }
}