钩子文档

get_meta_sql

💡 云策文档标注

概述

get_meta_sql 是一个 WordPress 过滤器,用于修改元查询生成的 SQL 语句。它允许开发者在元查询的 JOIN 和 WHERE 子句生成后,进行自定义调整。

关键要点

  • 过滤器名称:get_meta_sql
  • 主要用途:过滤元查询的 SQL 语句,包括 JOIN 和 WHERE 子句
  • 参数:包括 $sql(SQL 数组)、$queries(元查询数组)、$type(元类型,如 'post'、'comment' 等)、$primary_table(主表)、$primary_id_column(主 ID 列)、$context(查询对象,如 WP_Query)
  • 引入版本:WordPress 3.1.0
  • 相关函数:WP_Meta_Query::get_sql() 用于生成 SQL 子句

📄 原文内容

Filters the meta query’s generated SQL.

Parameters

$sqlstring[]
Array containing the query’s JOIN and WHERE clauses.
$queriesarray
Array of meta queries.
$typestring
Type of meta. Possible values include but are not limited to 'post', 'comment', 'blog', 'term', and 'user'.
$primary_tablestring
Primary table.
$primary_id_columnstring
Primary column ID.
$contextobject
The main query object that corresponds to the type, for example a WP_Query, WP_User_Query, or WP_Site_Query.

Source

return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type, $primary_table, $primary_id_column, $context ) );

Changelog

Version Description
3.1.0 Introduced.