WD-40 isn't actually a true lubricant. WD stands for "water displacing" and its main use is as a solvent or rust dissolver.
The lubricant-like properties of WD-40 come not from the substance itself, but from dissolving components. And the effect doesn't last.
WD-40 can be a good substance to start with — it can help clean up rust or other grime. But depending on what you're working with, you should probably follow up WD-40 with use of a true lubricant such as one based on silicone, grease, Teflon, or graphite.