The solution given by @RolandoMySQLDBA will give you all posts because you have a *
and not a +
. The *
means to return zero or more matches, which is not what you want. In this case, you actually don’t need either, but just to match the first character. Try this:
$sql .= $wpdb->prepare( " AND $wpdb->posts.post_name REGEXP '^[0-9]'");