meta_query search names when they have middle initials

The easiest approach in such cases is to set some other custom field which you’ll use for searching.

So if the name looks live that:

<first_name> <initial> <last_name>

Then you can create another field which will contain:

<first_name> <initial> <last_name>#<first_name> <last_name>#<last_name> <first_name>

(The # character is a separator, so you should use any character that will never occur in the fields your separating)

Then you can use this field for searching. You’ll be able not only to search for John Doe, but for Doe John too.

All you have to do is:

  1. When saving posts (for example using save_post hook), make sure the special field for searching is updated.
  2. Use that field in your query instead of original field.

This approach can be used much wider for searching. Whenever you want to search posts by many fields using LIKE comparison and you are not sure the format of query string the user will put (addresses, and so on), such special field for searching makes sense.