RyanStonebraker
New member
I was trying to create a code event listener that would register when a thread was initially created. When this happened, I wanted to get the post_id of the first post in this thread. In order to do this, I looked into the Forum class extension of Entity and found a field called last_post_id. However, when I logged last_post_id, it was consistently 0. To get around this, I found the fields last_thread_title and last_post_date, also present in the Forum class extension. I used these fields in conjunction with the Finder looking at the table xf_thread to try and get last_post_id from here, but this also came back as 0. What I ended up having to do was get the thread_id and then use the Finder again to look at xf_post and get the post_id from there. My question now is, is last_post_id being 0 a bug? Also, is there a better way to create a code event listener for thread creation?
Code Used:
Code Used:
PHP:
$thread_title = $entity->last_thread_title;
$post_date = $entity->last_post_date;
$thread_finder = \XF::finder('XF::Thread');
$thread_id = $thread_finder->where('title', $thread_title)->where('post_date', $post_date)->fetchOne()->thread_id;
$post_finder = \XF::finder('XF::Post');
$post_id = $post_finder->where('thread_id', $thread_id)->fetchOne()->post_id;