Conditional tag for comments

The comments popup page contains a loop of the comments, which can be checked by an is comments popup() conditional, that returns either true or false. However, i don’t see this feature being used in modern development. This might be the only place containing a direct loop of comments.

The $wp_query itself does not contain any comment data, except whether the post has any comments or not (and how many of them exist). The comment themselves are called later in the template files (such as single.php) by using a loop like this:

while ( have_posts() ) { 
    the_post(); 
    get_template_part( 'SOME TEMPLATE HERE' ); 
    comments_template();
}

The comments_template() itself will use WP_Comments_Query() to query a list of comments. So, to be on a comment loop means to be on a page or post template. So the conditional posted in the question won’t help, unless we change it like this:

if ( is_single() || is_attachment() || is_page() ) {
    // post, page, attachment
    update_post_meta($id, $meta_data, $meta_value);
    if(have_comments()) {
        // Run some stuff here
    }
} elseif (is_author()) {
    // author page
    update_user_meta($id, $meta_data, $meta_value);
} elseif ( is_category() || is_tag() || is_tax() ) {
    // taxonomies
    update_term_meta($id, $meta_data, $meta_value);
}

Which will update both comments and posts at the same time.

But there is a filter, which will trigger whenever comment_template() function is called in the template files, so it might be a place to hook and update the comments meta:

add_filter( "comments_template", "update_comments_meta" );
function update_comments_meta($comment_template){
    global $post;
    if ( have_comments() ){
        // Do some stuff here
    }
    return $comment_template;
}