Each electromagnet has two poles, so the total force on a given magnet due to another magnet is equal to the vector sum of the forces of the other magnet's poles acting on each pole of the given magnet.