hook_views_query_alter

Views - How to exclude nodes marked for menu display

15 October 2025
Problem: Your client needs a Views listing for the homepage that excludes any nodes currently being displayed in a menu. Out-of-the-box Views filters can't quite handle this specific logic.

Solution: Learn how to leverage hook_views_query_alter() to dynamically modify your Views query! This advanced Drupal technique allows you to perform a LEFT JOIN on the menu_link_content_data table and add a WHERE clause to filter out nodes that have an associated menu link, giving you precise control over your content listings.