The Earth's magnetic field is similar to that of a bar magnet tilted 11 degrees from the spin axis of the Earth. The problem with that picture is that the Curie temperature of iron is about 770 C . The Earth's core is hotter than that and therefore not magnetic. So how did the Earth get its magnetic field?
The Earth's magnetic field is attributed to a dynamo effect of circulating electric current, but it is not constant in direction. Rock specimens of different age in similar locations have different directions of permanent magnetization. Evidence for 171 magnetic field reversals during the past 71 million years has been reported.