Check if someone recently commented in one of my posts

It seems you have to check with a current user.

As it’s a notification system, you’ll have to take all post Ids by current user and check it globally.

Otherwise, you have to check in every single post.
And you will not able to access the values from anywhere of the website.

So this is the codes to get the latest (comment, comment user id) … globally 🙂

// Grab all posts' (array)ids by current user
function current_author_post_ids() {

    global $current_user;

    $args = array(
        'author' => $current_user->ID,
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => -1
    ); // get all posts


    $author_posts = get_posts($args);

    // check if only one id return
    if (count($author_posts) > 1) {

        $allIds = array();

        foreach ($author_posts as $c_post) :
            $allIds[] = $c_post->ID;
        endforeach;

        return $allIds;

    } else {

        return $author_posts[0]->ID;

    }

}

function get_last_comment_and_author_id() {
    $args = array(
        'number' => '1',
        'post__in' => current_author_post_ids(),
        'orderby' => 'post_date',

        // order by Time Stamp Here
        // 'oderby' => 'meta_type' TIME

        'order' => 'DSC',
        'posts_per_page' => 1
    ); // get only one comment


    // Get the latest comment

    $comments = get_comments($args);

    foreach ($comments as $comment) :
        echo 'Last author ID =' . $comment->user_id . '<br>';
        echo 'Last author=" . $comment->comment_author . "<br>';
        echo 'Last Comment=" . $comment->comment_content;
    endforeach;

}

To get the values, you can run this function

 <?php echo get_last_comment_and_author_id(); ?>