View - show predetermined result set prior to exposed filter Standard behavior: I have a view that has some filters exposed to the user. When the user first visits the page, the exposed filters are empty and the view just shows everything. When the user modifies a filter, the view shows a subset of the results based on their query.

Ideal behavior: When the user first visits the page, and have not performed a search using the exposed filters yet, I'd like the view to show a predetermined set of results... like a group of highlighted* items that I'd want the user to see. Then they perform a search, and the view acts normally.

Is this possible?



*These "highlighted" items would be determined by a field in the node.
All you need to do is:


Create a Boolean field to mark highlights (Let's say field_highlights)
Add a views filter for field_highlight with the following detail:

2.1. Not exposed

2.2. Operation: Is one of

2.3. Options: Select both 'On' and 'Off'
Write a bit of magic code which:

3.1. Checks if the user has not used the exposed filters yet

3.2. Alters the options for our filter to only show 'On' values 


Last part sounds difficult? Actually it's not:

    &lt;?php

    /**
     * Implements hook_views_pre_view().
     *
     * Applys a custom filter if there is no filter applyed by user
     *
     */
    function YOURMODULE_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
        // Make sure we are altering the right view
        if ($view-&gt;name == 'YOUR_VIEW_NAME') {
            // Get the user input for exposed filters
            $user_input = $view-&gt;get_exposed_input();
            // Check if there is no user input 
            if (empty($user_input)) {
                // The filter name for selecting highlighted items
                $filter_name = 'field_highlighted_value'; // Figure the filter name by looking at the exported views
                // Getting the filter array
                $filter = $view-&gt;get_item($view-&gt;current_display, 'filter', $filter_name);
                // Setting the value to TRUE
                $filter['value'] = array(1=&gt;'1');
                // Saving the changes to the filter
                $view-&gt;set_item($view-&gt;current_display, 'filter', $filter_name, $filter);
            }
        }
    }