Consider these two expressions
Do you have anything to eat?
Have you had anything to eat?
In the first expression I am definitely asking someone if he has something to eat. But in the second expression whether had means to eat or to have something like the first expression?
Idiomatically, the second sentence means what you suspect it means: Have you eaten anything recently?
I suppose that phrase could be used where the meaning gets closer to the first question, but you’d have to insert some context and additional words to make the phrase mean something different than its usual idiomatic meaning.
Consider this mother, who gasps in horror the first time she visits her son in her new apartment, and opens the refrigerator door to find nothing except beer:
Mom: Oh my goodness! There’s no food in your fridge!
Son: Why do I need food? I work at a restaurant.
Mom: So your refrigerator never has food in it?
Mom: Have you had anything to eat in here, since you’ve moved in?
Son: Not really.
Mom: Come on; I’m taking you grocery shopping.
There – I’ve made the meaning of the words in your second question more closely mirror that of your first. In order to do so, though, I had to carefully insert it into a very specific context.
Taken by itself, “Have you had anything to eat?” normally means “Have you eaten anything lately? (Or are you getting hungry?)”