0

I have two different comments, but both are related to the same post type. The first comments in this way:

<?php
    if (isset($_POST['submit_tickets'])){
        $tickets_reply =  $_POST['tickets_reply'];
            $my_tickets_comment_data = array(
                'comment_post_ID' => $post->ID,
                'comment_content' => $tickets_reply,
                'comment_author' => $current_user->display_name,
                'comment_author_email' => $current_user->user_email,
                'comment_type' => 'comment',
                'user_id' => $current_user->ID,
                'comment_date' => get_the_date(),
                'comment_approved' => 1,
            );
                $commentid  = wp_insert_comment($my_tickets_comment_data);
    }

And this is how the second comment in the same post type looks:

                $comment_array = array(
                    'comment_content' => $mail['body'],
                    'comment_post_ID' => $posts[0]->ID,
                    'comment_author'  => ucwords(strstr($mail['header']->fromaddress, '<',true)),
                    'comment_author_email' => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
                    'comment_type'  => 'comment',
                    'comment_date'  => $mail['header']->Date,
                    'comment_approved' => 1,
                    'comment_meta'  => array(
                        'message_id' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true))),
                );
               $commentid =  wp_insert_comment($comment_array);
            }

This is how I display the comments:

/*get replies*/         
    $args = array(
        'user_id' => $current_user->ID,
        'post_id' => $post->ID,
        'type' => 'comment'     
    );      
$get_tickets_replies = get_comments($args);
    function filter_media_comment_status( $open, $post_id ) {
        $post = get_post( $post_id );
        if( $post->post_type == 'my-post-type' ) {
        return false;
   }
    return $open;
}
add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 );
    ?>              
<div class="reply-detail">
    <?php foreach ($get_tickets_replies as $replies) { ?>
    <div class="avatar-message user-message">
    <div class="panel-image user">
    <img class="avatar" alt="Avatar"src="//www.gravatar.com/avatar/394b69f87b5e402481cbf8ce069ce8ac?s=80&amp;d=mm">
    </div>
    <div class="panel-heading user"> 
    <!---<?php echo ($replies->comment_date_gmt); ?>--->
                                        
    <h6><?php echo ($replies->comment_author); ?></h6>
    <span class="date"><b>Posted:</b> <?php echo date('F j, Y'); ?></span>
    </div>
    <div class="panel-reply user">
    <p><?php echo $replies->comment_content; ?></p>
    </div>
    </div>
<?php   }  ?>

The display code (above) and first comments are in the same file, or you can say the same plugin, and the second plugin is inserting comments from emails, and both comments are inserted to the same post type.

In the first plugin, the comments can be inserted from the frontend or backend. But in the second plugin, the comments are email replies. Both the plugin use the same custom post type, but the second plugin only deals with emails, whereas in the first plugin the post is created manually from the WP dashboard.

You can see the two different wp_insert_comment() calls and their arrays/args.

Now my question is, the display code only works for the first comment, so how can I display the second comments?

11
  • I edited your post to clarifiy the question based on your comments, but if you noticed any mistakes in the wording I used, just edit your post and correct the mistakes.. also, I've deleted my previous comments, so you should delete yours, too.
    – Sally CJ
    Jan 20, 2022 at 3:35
  • ok, It is all fine. Thanks for the edit.
    – Rohit kc
    Jan 20, 2022 at 5:04
  • So I wanted to confirm one thing: Right now, your display code is displaying comments by the currently logged-in user, right? And the comments from the 2nd plugin do not have a user ID, only email as the unique identifier; is that correct? If so, is there something that can "connect" the current user with the emails (the "second comments")? (maybe a special user meta?) If no, then I don't see how would it be possible to display the emails when the user_id argument is set in your $args.
    – Sally CJ
    Jan 20, 2022 at 6:33
  • However, if you wanted to have two display divs/areas - one for displaying the first comments and the other for the second comments, then that one might be possible.
    – Sally CJ
    Jan 20, 2022 at 6:40
  • The 2nd plugin works with email. The posts are email posts and the comments are email replies also the users are also created when emails are inserted as post. So, when or if the comments are displayed in the frontend it will show the user who sent the email. And displaying the first comments and second comments separately won't help as the comments in the email post can be both email replies or from the first plugin as well.
    – Rohit kc
    Jan 20, 2022 at 11:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.