During solar minimum, the sun's magnetic field is close to a dipole, with one north pole and one south pole, similar to Earth's magnetic field. But as we shift toward solar maximum, "the sun's ...
If you bring a north pole and a south pole together, they will attract. Earth's core contains liquid iron which moves around. Iron is magnetic so the liquid iron causes Earth to have a magnetic field.