How To Use Negate options in contextual filter - Drupal views ?

   comments Share with:

In this blog, we are going to explain that how to show result with negate option in views i.e situation like "is not equal current nid" filter. Showing reverse result using Drupal Views need not required any additional modules, it's already an option 'Exclude' available in Views to achieve reverse result.

Lets see the following steps by which we can achieve the view result with condition like "is not equal current nid":---

  1. Create your view as your requirement.
  2. Expand the 'Advanced' options on the right side and Click 'Add' next to 'Contextual Filters'.


  3. Type 'nid' in the search box filtering the results to just 'Content: Nid' then check this box and click 'Apply (all displays)' button.


    • Select "Provide default value" next to When the filter value is NOT available
    • Select "PHP Code" next to Type
    • Enter "return arg(1);" under PHP contextual filter code textarea.


  4. Now Expand the 'More' at the bottom.
  5. Check the box 'Exclude' and click 'Apply (all displays)' button.


  6. Now check view output, you will found the nodes list excluded the current node.

Add new comment