wpdb::esc_like PHP Method

esc_like() public method

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 ) );
Since: 4.0.0
public esc_like ( string $text ) : string
$text string The raw text to be escaped. The input typed by the user should have no extra or deleted slashes.
return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare() or real_escape next.
    public function esc_like($text)
    {
        return addcslashes($text, '_%\\');
    }

Usage Example

コード例 #1
0
 function posts_where($where, &$wp_query)
 {
     global $wpdb;
     if ($title = $wp_query->get('like_title')) {
         $where .= " AND " . $wpdb->posts . ".post_title LIKE '%" . esc_sql(wpdb::esc_like($title)) . "%'";
     }
     return $where;
 }
All Usage Examples Of wpdb::esc_like