Why does the Earth even have a magnetic field? From my knowledge of magnetism, if a magnet is heated to a certain temperature, it loses its ability to generate a magnetic field. If this is indeed the case, then why does the Earth's core, which is at a whopping 6000 °C — as hot as the sun's surface, generate a strong magnetic field?
 A: The crucial part is that earth's outer core is fluid, and that it's conductive. That the material happens to be iron which we know as ferromagnetic is actually rather unimportant, because the geomagnetic field is not created as a superposition of atomic spins like in a permanent magnet. Rather, it's generated via Ampère's law from macroscopic currents, like in an electromagnet made from a wound copper coil with a current going though it. (It is an electromagnet, really.)
The reason there are such currents is that the liquid is in convective motion, probably fuelled by thermal transport from the radioactive decay in the inner core. When a conducting liquid moves, it “pulls any magnetic field line with it”. Starting from a small background field, if the flow is complex and rapid enough, this tends to amplify over time.
This dynamo effect can be described theoretically, numerically, or with laboratory-scale experiments using liquid sodium (sodium being nonmagnetic, but a good conductor and easy to melt). It is not hindered by high temperatures (rather, the high temperatures are often necessary to ensure flow and/or conductance). And it takes place not only on Earth, but also on many other objects:


*

*The Sun's dynamo uses the plasma (hydrogen/helium), i.e. the fluid is not a metal at all, nor a liquid, but an ionised gas. This is again driven by convection.

*The gas giants Jupiter and Saturn have dynamos that apparently consist of hydrogen too, but because of the comparatively low temperatures but still immense pressure it's likely in a metallic state.

*The ice giants Neptune and Uranus have unusually tilted and irregular magnetic fields. It is assumed that this is due to a dynamo not in the core region like for earth, but in a shell rather higher up in the planet's structure. It probably consists of a mixture of hot, pressurised, liquid water, ammonia and methane, which has enough dissolved ions to be a good conductor.

*Rocky planets and moons often have earth-like dynamos, most notably Mercury and Ganymede.


Remanent magnetism, the kind that we know from permanent magnets and which only works below the Curie temperature, is only important on rocky planets which don't have a dynamo. The most prominent example is Mars, but this magnetic field is much weaker than the aforementioned dynamo-generated ones.
A: The core of the Earth isn't a giant bar magnet in the sense that the underlying principles are different. A bar magnet gets its magnetic field from ferromagnetism while Earth's magnetic field is due to the presence of electric currents in the core.
Since the temperature of the core is so hot, the metal atoms are unable to hold on to their electrons and hence are in the form of ions. These ions and electrons are in motion in the core which forms current loops. The individual currents produce magnetic fields which add up to form the magnetic field around the Earth.
