Skip to content

Instantly share code, notes, and snippets.

@danreb
Created September 19, 2013 09:15
Show Gist options
  • Save danreb/6621014 to your computer and use it in GitHub Desktop.
Save danreb/6621014 to your computer and use it in GitHub Desktop.
Useful in removing duplicate node in taxonomy term display page when using views
<?php
/*
* Check node ID to remove duplicate result.
*
*/
function MODULENAME_views_pre_render(&$view) {
//dpm($view->name);
if ($view->name == 'taxonomy_term') {
$nids = array();
foreach ($view->result as $row) {
/* Do we have this nid already? */
if (!isset($nids[$row->nid])) {
/* No, add this row to the output array */
$result[] = $row;
/* record that we have this nid */
$nids[$row->nid] = $row->nid;
}
}
/* Return the new results set */
return $view->result = $result;
}
}
?>
@danreb
Copy link
Author

danreb commented Sep 19, 2013

Drupal 7 code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment