Filter hook 'query'

in WP Core File wp-includes/class-wpdb.php at line 2228

View Source

query

Filter Hook
Description
Filters the database query. Some queries are made before the plugins have been loaded, and thus cannot be filtered with this method.

Hook Information

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

Hook Parameters

Type Name Description
string $query Database query.

Usage Examples

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

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

Source Code Context

wp-includes/class-wpdb.php:2228 - How this hook is used in WordPress core
<?php
2223  		 *
2224  		 * @since 2.1.0
2225  		 *
2226  		 * @param string $query Database query.
2227  		 */
2228  		$query = apply_filters( 'query', $query );
2229  
2230  		if ( ! $query ) {
2231  			$this->insert_id = 0;
2232  			return false;
2233  		}

PHP Documentation

<?php
/**
		 * Filters the database query.
		 *
		 * Some queries are made before the plugins have been loaded,
		 * and thus cannot be filtered with this method.
		 *
		 * @since 2.1.0
		 *
		 * @param string $query Database query.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/class-wpdb.php
Related Hooks

Related hooks will be displayed here in future updates.