The pike in this game is designed as an anti-cavalry unit. It does not fare so well against other infantry; it is capable of holding the line and keeping the enemy tied up for a time, but another unit is usually needed to deliver the coup de grace and start the rout. This is the first thing you need to remember when using them. The second thing is that they need to be frequently checked to see if they have dropped their pikes and are fighting with their swords instead. This is the major issue with pikemen. Their sword is a poor secondary weapon, far less lethal than the pike, and units which fight using it tend to die nasty deaths in relatively short order. Thus the usage of pikemen revolves around forcing them to use their pikes.
So far the most reliable way discovered to do this requires a lot of micromanagement. Unless standing stationary receiving a charge guard mode should be turned off, and when taking a charge it should be turned off once the lines are joined as this will allow your men to fight instead of focus on dressing their lines and leaving half the soldiers out of fighting range.
The attack should be ordered with a single click; this should begin combat with your pikemen stabbing away with their primary weapons. As time passes more and more men will swap to using their swords because individual enemy soldiers have made it past the pike points. When you see this you should turn off spear wall formation, immediately re-engage it, and reissue the single click attack order on the target. The majority of your men will magically produce pikes and start stabbing away once again. It’s usually necessary to do this multiple times with each unit during the course of a melee, adding up to a lot of micromanagement. If your pikemen are engaged against infantry you will need to coordinate some flanking forces whilst doing this, and it can all get very fiddly. Practice is the key, and custom battle mode offers unlimited amounts of it for those willing to invest the time.