How to use mysql LIKE with wpdb?
as per title I need to use
operator to delete a row on db programmatically with $wpdb.
I wanna use
$wpdb->delete to remove an occurrency but I don’t know how to set the
LIKE operator because in
WHERE it requires an array that assign a single value or another array.
I ask you if this syntax is correct.
$wpdb->delete('wp_posts', array('post_type' => 'flamingo_inbound', 'post_content' => '%'.$mail.'%'));
Thanks in advance
According to the Codex, the delete method will not accept the
LIKE operator. You’ll be better off just using the query method.
$query = $wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_type = 'flamingo_inbound' AND post_content LIKE %s", '%'.$mail.'%'); $wpdb->query($query);
$mail = $wpdb->esc_like($mail);