It is narrated from Khalid bin Abi al-Salt (may Allah have mercy on him) that he said: I was with Umar bin Abd al-Aziz (may Allah have mercy on him) during his caliphate, and Irak bin Malik (may Allah have mercy on him) was also with him. Umar bin Abd al-Aziz (may Allah have mercy on him) said: "For such and such a length of time I have neither faced the qiblah nor turned my back to it when urinating or relieving myself." Irak (may Allah have mercy on him) said: Sayyidah Aishah (may Allah be pleased with her) narrated to me that when what people were saying about this reached the Messenger of Allah (peace and blessings be upon him), he (peace and blessings be upon him) ordered that his toilet seat be turned to face the qiblah.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 441