I heard the Messenger of Allah ﷺ say, "There are four whose rewards continue to flow to them after death. A man who dies stationed in the path of Allah, a man who taught knowledge, his reward continues for him as long as it is acted upon, a man who gave a charity, its reward continues for him as long as it remains in effect, and a man who left behind a righteous child who prays for him."
حدثنا يحيى بن إسحاق حدثنا ابن المبارك أخبرنا ابن لهيعة عن خالد بن أبي عمران عمن حدثه
سمعت رسول الله ﷺ يقول أربع تجري عليهم أجورهم بعد الموت رجل مات مرابطا في سبيل الله ورجل علم علما فأجره يجري عليه ما عمل به ورجل أجرى صدقة فأجرها يجري عليه ما جرت عليه ورجل ترك ولدا صالحا يدعو له
Its isnad is daif due to the anonymity of the narrator from Abu Umama. The hadith is sahih, previously mentioned in 22148.22219m - Hasan narrated to us, Ibn Lahia narrated to us, from Khalid bin Abu Imran, from Abu Umama, from the Messenger of Allah ﷺ, and he mentioned it, except that he said, "Whoever teaches knowledge is granted the same reward as one who acts upon it."Hasan (22219m). Its isnad is hasan.