There is no reason that the meta query should not work. The database column is varchar
so your number is going to be treated as a string. I tested as best I can without having your database and the testing seems to confirm that.
I think you are going to get a lot of spurious matches. The default LIKE
search will put a %
wildcard at each end of the string so that 123
will match anywhere in the string, for example, here– 12345678
— but also here– 45678123
. I suspect that you only want a one sided LIKE
so that 123
matches but at the front of 12345123
but not the end. You need a filter for that.
function one_sided_like($sql) {
remove_filter('get_meta_sql','wildcard_meta_like');
$pat="%([^%]*)%";
preg_match('|'.$pat.'|',$sql['where'],$matches);
if (!empty($matches[1])) {
$sql['where'] = str_replace($matches[0],$matches[1].'%',$sql['where']);
}
return $sql;
}
add_filter('get_meta_sql','one_sided_like');