XF 2.0 Get post_id after replier

LPH

Well-known member
This is the current code and need to figure out the correct way to grab the post_id after the save():

PHP:
$visitor = \XF::visitor();
$message = $commentdata->comment_content;

if ( $thread_id !== false && $thread_id !== null && $visitor['is_banned'] != 1 ) {

 $replier = \XF::app()->service('XF:Thread\Replier', $thread);
 $replier->setMessage($message);
 $replier->save();

 $post_id = $replier;
}

I tried $replier['post_id'] and see it is an object. This makes sense based on the var_dump / dump but now I'm uncertain how to get the post_id or if it is even possible.

Code:
An exception occurred: [Error] Cannot use object of type XF\Service\Thread\Replier

Thank you for any suggestions.
 
The post is returned by the save() call:

PHP:
$post = $replier->save();

$id = $post->post_id;
 
Thank you @Jeremy P -- I was banging my head up against this for days.

:eek:

by using $post = $replier->save(); instead of just $replier->save(); was the key!

Now comments from WordPress flow to XenForo and XenForo replies flow to WordPress. Wahooo !
 
Back
Top Bottom