Filter hook 'post_search_columns'

in WP Core File wp-includes/class-wp-query.php at line 1473

View Source

post_search_columns

Filter Hook
Description
Filters the columns to search in a WP_Query search. The supported columns are `post_title`, `post_excerpt` and `post_content`. They are all included by default.

Hook Information

File Location wp-includes/class-wp-query.php View on GitHub
Hook Type Filter
Line Number 1473

Hook Parameters

Type Name Description
string[] $search_columns Array of column names to be searched.
string $search Text being searched.
WP_Query $query The current WP_Query instance.

Usage Examples

Basic Usage
<?php
// Hook into post_search_columns
add_filter('post_search_columns', 'my_custom_filter', 10, 3);

function my_custom_filter($search_columns, $search, $query) {
    // Your custom filtering logic here
    return $search_columns;
}

Source Code Context

wp-includes/class-wp-query.php:1473 - How this hook is used in WordPress core
<?php
1468  		 *
1469  		 * @param string[] $search_columns Array of column names to be searched.
1470  		 * @param string   $search         Text being searched.
1471  		 * @param WP_Query $query          The current WP_Query instance.
1472  		 */
1473  		$search_columns = (array) apply_filters( 'post_search_columns', $search_columns, $q['s'], $this );
1474  
1475  		// Use only supported search columns.
1476  		$search_columns = array_intersect( $search_columns, $default_search_columns );
1477  		if ( empty( $search_columns ) ) {
1478  			$search_columns = $default_search_columns;

PHP Documentation

<?php
/**
		 * Filters the columns to search in a WP_Query search.
		 *
		 * The supported columns are `post_title`, `post_excerpt` and `post_content`.
		 * They are all included by default.
		 *
		 * @since 6.2.0
		 *
		 * @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.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/class-wp-query.php
Related Hooks

Related hooks will be displayed here in future updates.