post_search_columns
Filters the columns to search in a WP_Query search.
The supported columns are post_title, post_excerpt post_content. They are all included by default.
Usage
add_filter( 'post_search_columns', 'wp_kama_post_search_columns_filter', 10, 3 );
/**
* Function for `post_search_columns` filter-hook.
*
* @param string[] $search_columns Array of column names to be searched.
* @param string $search Text being searched.
* @param WP_Query $query The current WP_Query instance.
*
* @return string[]
*/
function wp_kama_post_search_columns_filter( $search_columns, $search, $query ){
// filter...
return $search_columns;
}
- $search_columns(string[])
- Array of column names to be searched.
- $search(string)
- Text being searched.
- $query(WP_Query)
- The current WP_Query instance.
Changelog
| Since 6.2.0 | Introduced. |
Where the hook is called
post_search_columns
wp-includes/class-wp-query.php 1473
$search_columns = (array) apply_filters( 'post_search_columns', $search_columns, $query_vars['s'], $this );