钩子文档

post_search_columns

💡 云策文档标注

概述

post_search_columns 过滤器用于在 WP_Query 搜索中指定要搜索的数据库列。默认情况下,搜索包括 post_title、post_excerpt 和 post_content 列。

关键要点

  • 过滤器名称:post_search_columns
  • 默认搜索列:post_title、post_excerpt、post_content
  • 参数:$search_columns(数组,要搜索的列名)、$search(字符串,搜索文本)、$query(WP_Query 实例)
  • 用途:允许开发者自定义 WP_Query 搜索时查询的数据库列
  • 相关函数:WP_Query::parse_search() 用于生成 WHERE 子句的 SQL
  • 引入版本:WordPress 6.2.0

📄 原文内容

Filters the columns to search in a WP_Query search.

Description

The supported columns are post_title, post_excerpt and post_content.
They are all included by default.

Parameters

$search_columnsstring[]
Array of column names to be searched.
$searchstring
Text being searched.
$queryWP_Query
The current WP_Query instance.

Source

$search_columns = (array) apply_filters( 'post_search_columns', $search_columns, $query_vars['s'], $this );

Changelog

Version Description
6.2.0 Introduced.