EP_WP_Query_Integration::action_pre_get_posts PHP Method

action_pre_get_posts() public method

Disables cache_results, adds header.
Since: 0.9
public action_pre_get_posts ( $query )
$query
    public function action_pre_get_posts($query)
    {
        if (!ep_elasticpress_enabled($query) || apply_filters('ep_skip_query_integration', false, $query)) {
            return;
        }
        /**
         * `cache_results` defaults to false but can be enabled.
         *
         * @since 1.5
         */
        $query->set('cache_results', false);
        if (!empty($query->query['cache_results'])) {
            $query->set('cache_results', true);
        }
        if (!headers_sent()) {
            /**
             * Manually setting a header as $wp_query isn't yet initialized
             * when we call: add_filter('wp_headers', 'filter_wp_headers');
             */
            header('X-ElasticPress-Search: true');
        }
    }