When the primary coil of a loaded transformer is connected to AC current, it generates a flux ...
loaded or unloaded, it doesn't matter. It can be conceptually easier to start with the unloaded case when trying to see how primary EMF controls the core flux.
that goes into secondary
the flux is in the core. It couples to both the primary and the secondary.
the loaded secondary induces voltage that generates its own back EMF induced flux
The voltage induced in the secondary, when applied across the load, causes a load current to flow in both the load and the secondary.
which cancels the flux generated by primary.
which current is of opposite sense to the primary current, so would tend to reduce the flux (not cancel) in the core. As the magnitude of the flux is determined by the magnitude of the primary voltage, it must stay constant. The primary current increases so that the total magnetising current, that is the algebraic sum of the primary and secondary current (which as the currents are more or less opposite in sign is often written as primary-secondary currents), remains constant.
What I don't understand is this cancellation happens when both fields have same polarity or different polarity?
The primary and secondary currents have opposite direction, so their individual fields would have different polarity.
Will North-North flux cancels each other or North-South flux cancels each other?
Talking about N and S poles is more useful when referring to bar magnets, or open solenoids. The field inside a transformer is closed. However, referring to the coils as solenoids, if the primary current produces a N pole at the top, the secondary current would produce a S pole.
Also my question is whether primary flux and secondary back EMF induced flux attract each other or repel each, (meaning whether they have same polarity or different polarity)?
Attraction and repulsion are terms that are more useful when physical objects can move. The primary and secondary coils are wound on the same former round the same coil. However, there is a sense in which the concept of attraction/repulsion can be used to get some insight into what's going on in a transformer.
Take a system like a stretched rubber band, whose two ends attract each other, or two magnets whose N poles repel each other, or a mass above the earth, that attracts it. Distort the system, pushing against the force you feel. In all cases, this is storing energy in the system. Now give it its freedom, stop distorting the system, and it will move to reduce the stored energy.
In a transformer or inductor core, the stored magnetic energy is proportional to the magnetising current squared. Not the primary current, or the secondary current, but the magnetising current, that is, their algebraic sum. If the secondary current was in the same phase as the primary current, their sum would increase, increasing the stored energy. That's not what energy storage systems do, they try to reduce their energy. This means that the secondary and primary current oppose each other, to reduce the net current, reduce the net magnetisation, and reduce the stored energy in the core.