I have extracted the reply emails. The original emails are saved as CPT and work as Tickets in my plugin. I want the reply email to go as a comment to the original email.
for($j = 1; $j <= $total; $j++){
$mail = $emails->get($j);
//This checks if the email is reply or not and if the email is reply make it comment to its original post.
if ((!empty($mail['header']->references )) && ($mail['header']->references ) == ($mail['header']->message_id )
{
$comment_array = array(
'comment_content' => $mail['body'],
'comment_post_ID' => ,
)
wp_insert_comment($comment_array);
}
}
I have distinguished the reply email and original email but I don’t how to keep those emails as comments to the original email.
This is how my wp_insert_post
looks like:
$post_array = array(
'post_content' => $mail['body'],
'post_title' => $mail['header']->subject,
'post_type' => 'faqpress-tickets',
'post_author' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
'post_status' => 'publish',
'meta_input' => array(
'User' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
'From' => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
'Email' => $mail['header']->Date,
'ticket_id' => $mail['header']->message_id,
),
);
//wp_insert_post( $post_array );
If anyone knows how to do it. It will be a great help.