Views how to remove node duplication when using fields with multiple values
! Legacy Drupal 7 code !
Recently, I displayed a list of companies using Views, and for some reason, Views was showing 1–3 identical entries, which was quite strange. I tried removing filters and sorting options, but it still duplicated entries. The issue turned out to be that the nodes had a date field with multiple values. These company nodes were being duplicated. Below is the solution to my— and possibly your—duplicate entries issue in Views:
Create a new module. In my case, it’s called sitemade
. Contents of the sitemade.info
file:
name = Views Remove Duplicates description = Removes duplicate nodes. Requires editing the module file to identify the views you want to affect. package = "Views" core = 6.x dependencies[] = views
Next, I create the sitemade.module
file:
<?php function sitemade_views_pre_render(&$view){ $used_nids = array(); if ($view->name == 'companies'){ if ($view->current_display == 'page_1'){ foreach ($view->result as $row){ if (!in_array($row->nid, $used_nids)){ $new_view_result[] = $row; $used_nids[] = $row->nid; } } $view->result = $new_view_result; } } }
Where 'companies'
is the name of my View, and 'page_1'
is the display name of my Views page. After adding this code, nodes in the View were no longer duplicated.
This solution in English, as well as other approaches to this issue, can be found here: