Filter hook 'comments_array'

in WP Core File wp-includes/comment-template.php at line 1593

View Source

comments_array

Filter Hook
Description
Filters the comments array.

Hook Information

File Location wp-includes/comment-template.php View on GitHub
Hook Type Filter
Line Number 1593

Hook Parameters

Type Name Description
array $comments Array of comments supplied to the comments template.
int $post_id Post ID.

Usage Examples

Basic Usage
<?php
// Hook into comments_array
add_filter('comments_array', 'my_custom_filter', 10, 2);

function my_custom_filter($comments, $post_id) {
    // Your custom filtering logic here
    return $comments;
}

Source Code Context

wp-includes/comment-template.php:1593 - How this hook is used in WordPress core
<?php
1588  	 * @since 2.1.0
1589  	 *
1590  	 * @param array $comments Array of comments supplied to the comments template.
1591  	 * @param int   $post_id  Post ID.
1592  	 */
1593  	$wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
1594  
1595  	$comments                        = &$wp_query->comments;
1596  	$wp_query->comment_count         = count( $wp_query->comments );
1597  	$wp_query->max_num_comment_pages = $comment_query->max_num_pages;
1598  

PHP Documentation

<?php
/**
	 * Filters the comments array.
	 *
	 * @since 2.1.0
	 *
	 * @param array $comments Array of comments supplied to the comments template.
	 * @param int   $post_id  Post ID.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/comment-template.php
Related Hooks

Related hooks will be displayed here in future updates.