There's a chance that food allergies can cause earaches, since earaches are commonly the result of ear infections and research has shown that food allergies are linked to ear infections. Children are the most common sufferers of both ear infections and food allergies. The way that food allergies work is your immune system mistakenly identifies certain proteins found in the foods you're allergic to as dangerous, even though they're perfectly safe. Then whenever you eat foods with those proteins in them, your immune system sends out an antibody called immunoglobulin E to handle the allergen. The antibody triggers a slew of chemicals to fight off the allergen; one of those chemicals is called histamine, and it's responsible for many types of allergic symptoms.
One of the symptoms of food allergies is swelling. Research has shown that among the parts of your body that can swell due to food allergies is the Eustachian tube that connects your throat to your ear. Bacteria-filled fluids typically pass through that tube; if it swells up, the fluid gets trapped in your middle ear. In the warm, dark recess behind your eardrum, the bacteria thrive and cause an ear infection. That ear infection can cause your ear to hurt.
The most common food-allergy causes for earaches are dairy products, wheat, corn, peanuts and oranges. If you suspect you have a food allergy that's causing your ears to hurt chronically, try to avoid eating those foods for a few weeks and see if the pain goes away. If it does, reintroduce them one by one to see if any of them cause the pain to return. If one does, you've found the culprit. You can check with your doctor for a professional diagnosis.