this will test for whether a custom page to display posts is active, and if so, set the query to the default
@param  WP_Query $query the original query recived from WordPress
@return WP_Query
961314
public static function handle_maybe_custom_posts_page( $query ) {
		if ( $custom_posts_page = get_option('page_for_posts') ) {
			if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
				return new \WP_Query(array('post_type' => 'post'));
			}
		}
		return $query;
	}
1105148
public function findActive($query, $options)
    {
        $query->where([
            $this->config('field') => $this->config('states.active'),
        ]);

        return $query;
    }
192392
public function current($query = false)
	{
		return ($query ? $this->getUri() : rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/'));
	}
1343729
public function scopeUnarchived($query)
    {
        $carbon = Carbon::parse('today midnight')->timezone('UTC');

        return $query
            ->where(function ($query) use ($carbon) {

                $query->whereIn('status', [Self::STATUS_RESERVED, Self::STATUS_CONFIRMED])
                    ->where('start_at', '<=', $carbon)
                    ->orWhere(function ($query) use ($carbon) {
                        $query->where('start_at', '>=', $carbon);
                    });
            });
    }
60268
private function _query($query)
    {
        $db = $this->_getConnection();
        if (is_resource($db)) {
            $res = @sqlite_query($db, $query);
            if ($res === false) {
                return false;
            } else {
                return $res;
            }
        }
        return false;
    }
1344348
public function setQuery($query)
    {
        $this->query = $query;
        parse_str($this->query, $this->query_array);
        return $this;
    }
880987
public static function fix_cat_wp_quirk( $query ) {
		if ( isset($query->query) && isset($query->query['category'])
				&& !isset($query->query['cat']) ) {
			$query->set('cat', $query->query['category']);
			unset($query->query['category']);
		}
		return $query;
	}
739073
private function postType(\WP_Query $query)
    {
        $type = $query->get('post_type');
        is_array($type) and $type = reset($type);

        $object = get_post_type_object($type);
        (is_object($object) && $object->has_archive) or $type = '';

        return $type;
    }
1088921
public function sortSortableColumns($query)
    {
        // don't modify the query if we're not in the post type admin
        if (!is_admin() || $query->get('post_type') !== $this->name) {
            return;
        }

        $orderby = $query->get('orderby');

        // if the sorting a custom column
        if (array_key_exists($orderby, $this->columns()->sortable)) {
            // get the custom column options
            $meta = $this->columns()->sortable[$orderby];

            // determine type of ordering
            if (is_string($meta)) {
                $meta_key = $meta;
                $meta_value = 'meta_value';
            } else {
                $meta_key = $meta[0];
                $meta_value = 'meta_value_num';
            }

            // set the custom order
            $query->set('meta_key', $meta_key);
            $query->set('orderby', $meta_value);
        }
    }
1228247
private function query($query)
    {
		if(!is_array($query)) {
			return q($query);
		} else {
			foreach($query as $v) {
				q($v);
			}
			return true;
		}
    }
1101520
public function execute($query)
    {
        $context = $this->getCommandContext();

        $context->query = $query;

        if ($this->getCommandChain()->run('before.execute', $context) !== false) {
            $context->result = $this->_adapter->execute(to_str($context->query));
            $this->getCommandChain()->run('after.execute', $context);
        }

        return $context->result;
    }
1113273
public function setQuery($query)
    {
        $this->query = null;
        if (is_string($query)) {
            $this->query = ltrim($query, '?');
        }
        return $this;
    }
1021705
public static function newInstanceFromWordpressQuery(\WP_Query $query)
    {
        $newQuery = new static;

        foreach (get_object_vars($query) as $property => $value)
        {
            $newQuery->$property = $value;
        }

        return $newQuery;
    }
979897
protected function doQuery(Query $query)
    {
        $result = static::db()->query($query);

        $this->where = null;

        return $result;
    }
18965
public function sort_columns($query)
    {
        // Bail if we are not on the correct admin page.
        if (! \is_admin() || !\in_array($this->name, $query->query_vars['taxonomy'])) {
            return;
        }

        $order_by = $query->get('orderby');

        // Check if the current sorted column has a sort callback defined.
        if (isset($this->sortable_columns[ $order_by ])) {
            $callback = "sort_{$order_by}_column";
            $this->{$callback}($query);
        }
    }
486031
public function setQuery($query = null)
    {

        try {

            // need to return << true
            $this->validator->verify($query, ['isNotNull', 'isAcceptLength']);

            if (false === $this->exact) {
                $this->query = ['query' => '%' . $query . '%'];
            }
            else {
                $this->query = ['query' => $query];
            }

        }
        catch(ExceptionFactory $e) {
            echo $e->getMessage();
        }

        return $this;
    }
1351898
public function scopeLive($query)
	{
		return $query->where($this->getTable().'.status', '=', Post::APPROVED)
			->where($this->getTable().'.published_date', '<=', \Carbon\Carbon::now());
	}