钩子文档

query

💡 云策文档标注

概述

本文档介绍 WordPress 中的 'query' 过滤器,用于过滤数据库查询。该过滤器在数据库查询执行前应用,但需注意某些查询在插件加载前执行,无法通过此方法过滤。

关键要点

  • 'query' 过滤器用于修改数据库查询字符串,通过 apply_filters('query', $query) 调用。
  • 参数 $querystring 表示数据库查询字符串,可直接在过滤器中调整。
  • 此过滤器在 wpdb::query() 方法中使用,但部分早期查询(如插件加载前)无法被过滤。

注意事项

  • 由于某些查询在插件加载前执行,使用此过滤器时需确保查询时机兼容,避免过滤失效。
  • 此过滤器自 WordPress 2.1.0 版本引入,使用时需考虑版本兼容性。

📄 原文内容

Filters the database query.

Description

Some queries are made before the plugins have been loaded, and thus cannot be filtered with this method.

Parameters

$querystring
Database query.

Source

$query = apply_filters( 'query', $query );

Changelog

Version Description
2.1.0 Introduced.