First half of escaping for LIKE special characters % and _ before preparing for SQL.
Use this only before wpdb::prepare() or esc_sql() . Reversing the order is very bad for security.
Example Prepared Statement:
$wild = '%';
$find = 'only 43% of planets';
$like = $wild . $wpdb->esc_like( $find ) . $wild;
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE %s", $like ); Example Escape Chain:
$sql = esc_sql( $wpdb->esc_like( $input ) );$textstringrequired
public function esc_like( $text ) {
return addcslashes( $text, '_%\\' );
}
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/esc_like