Fetch Forum ID by Thread ID in Non-Object


Well-known member
As the title says, I'm trying to fetch the forum id (node_id) by the 'thread_id'. I tried to use the $this->getModelFromCache['XenForo_Model_Forum'] method, so I could use getForumByThreadId, but I guess I can't do that where I'm trying to do it. I get the following error: Fatal error: Using $this when not in object context in /dirs/to/myAddon/Listener.php on line 165.

Is there a way to do this, somehow, without having to make another call to the dB?

Chris D

XenForo developer
Staff member
You're trying to use $this in your Listener which won't work because it's not in an object context.

Also, the getModelFromCache function won't be available in your Listener so trying to call it as if it is won't work.

The correct way to do this in a Listener is:



Well-known member
Thanks Chris Deeming. That did add an additional query to each thread view, but it works.


Well-known member
Inside the thread view you have access to


what event is yous listener using? template hook?