In general, magnetic fields are produced by electrical currents. There are at least two ways in which to get magnetic fields which may be relevant to planets:
An example of the above effects can be seen in an electromagnet. Both of the above produce magnetic fields with the familiar shape of a bar magnet:
In the above, iron filings are placed near a bar magnet. The iron filings align themselves along the magnetic field lines. Amazingly enough, if you look at the magnetic field of the Earth,
it appears to be very similar to the simple bar magnet.
The interior of the Earth (and most of the other Terrestrial planets) is (are) too hot for a permanent bar magnet to exist. So, in order for the Earth to have a magnetic field, it seems as if the interior of the Earth must be able to support strong electrical currents. This suggests that the core of the Earth should be something like liquid (molten) iron.
This important property of the core of the Earth thus follows simply from the fact that the Earth has a reasonably strong magnetic field!
