The same way your heart "knows" how to beat - it's a lower level function that happens without your conciousness. That's why people who are brain dead still live and breathe and swallow and digest and their hearts livers and kidneys still do their job.
>>how are they hard wired to search for milk
The ones who didn't died, to put it bluntly. Obviously not human babies, this evolutionary step happened long long time before the earliest hominids.