They were very close in those years so the confusion is understandable; there are even rumors that it was an alliance sealed by marriage as in medieval times.
The current situation of al-Qaida and the Taliban is less clear - especially as al-Qaida is just a shadow of its former self; while the Islamic State seems to be fighting the Taliban.
Basically the Taliban were host to al-Qaida in Afghanistan. Obviously al-Qaida also has ties with some rich members in the gulf states.
So in summary the war against Afghanistan after 9/11 made considerable sense, but there was no plan afterwards. The war in Iraq made less sense.