How does the Sun's magnetic field continue to exist at such high temperatures? The temperature at the surface of the Sun is apparently well above 5000 C; I'm assuming the layers beneath the surface may be even hotter.
At school, we learned that heating a metal beyond a certain temperature, specific to each metal, would demagnetize the magnet. 
How does the Sun's magnetic field continue to exist at such high temperatures?
 A: If the sun's internal plasma was at rest (the sun would have to stop rotating and other factors would need to occur), then I believe the magnetic field would dissipate and dissolve, essentially being 'demagnetized'.
However, because the star is rotating, and different layers of it at varying rates, the churning of the plasma (which is charged) generates the magnetic field as it moves past other charged plasma.
From Wikipedia:

A stellar magnetic field is a magnetic field generated by the motion of conductive plasma inside a star. This motion is created through convection, which is a form of energy transport involving the physical movement of material. A localized magnetic field exerts a force on the plasma, effectively increasing the pressure without a comparable gain in density. As a result, the magnetized region rises relative to the remainder of the plasma, until it reaches the star's photosphere. This creates starspots on the surface, and the related phenomenon of coronal loops

Also, a central part you're missing in the relationship to metals on earth is that you're not reaching a plasma state with the metal. Above a certain temperature, a solid metal will reconfigure itself into random alignment (no aligned charges), but if you go too far and make it a plasma, it's essentially all charged nuclei. This just isn't discussed because a majority of people don't tend to make metals into plasmas on a very routine basis.
A: The solar dynamo is responsible for the magnetic field. It has nothing to do with a magnet and thus is not affected by hight temperature. The sun is made of plasma which flows at the velocity V. This flow creates an electric field E=VxB, this electric field runs a current j through Ohm's law which in turn creates a magnetic field. The interaction between the current and the magnetic field creates a net force jxB that runs the plasma velocity V leading to a self sustained magnetic field.
More details can be found there:
http://rsta.royalsocietypublishing.org/content/360/1801/2741.full.pdf
http://www.scholarpedia.org/article/Solar_dynamo
A: The current answers point into the wrong direction. The right direction, in my opinion, is indicated in the comment of dmckee. 
The problem is with your intuition that high temperature destroys a magnetic field. This is wrong as we can see in numerous experiments.
It is correct, however, that there is a temperature at which the particular mechanism by which a magnetized piece of iron keeps up its magnetic field breaks done. The way iron produces a magnetic field is connected with certain properties of the iron atoms - and it is this property which is lost.
High temperature destroys the mechanism of iron (and some other metals) to keep a magnetic field, not the mechanism by which a moving charge produces a magnetic field.
In the sun the magnetic field is generated by moving charges. In iron the magnetic field is generated by a particular alignment of spin structures in the crystalline structure of the metal. Heat leads to movement of the atoms and destroys this crystalline structure.
