The comments_list_table_query_args WordPress PHP filter allows you to modify the arguments for the comment query in the comments list table.
Usage
add_filter('comments_list_table_query_args', 'my_custom_comments_list_table_query_args');
function my_custom_comments_list_table_query_args($args) {
// your custom code here
return $args;
}
Parameters
- $args (array) – An array of get_comments() arguments.
More information
See WordPress Developer Resources: comments_list_table_query_args
Examples
Filter comments by a specific author email
add_filter('comments_list_table_query_args', 'filter_comments_by_author_email');
function filter_comments_by_author_email($args) {
$args['author_email'] = '[email protected]';
return $args;
}
Exclude specific comment IDs from the comments list
add_filter('comments_list_table_query_args', 'exclude_specific_comment_ids');
function exclude_specific_comment_ids($args) {
$args['comment__not_in'] = array(1, 3, 5);
return $args;
}
Show only comments with a specific meta key and value
add_filter('comments_list_table_query_args', 'show_comments_with_specific_meta');
function show_comments_with_specific_meta($args) {
$args['meta_key'] = 'custom_meta_key';
$args['meta_value'] = 'custom_value';
return $args;
}
Order comments by comment karma in ascending order
add_filter('comments_list_table_query_args', 'order_comments_by_karma_asc');
function order_comments_by_karma_asc($args) {
$args['orderby'] = 'comment_karma';
$args['order'] = 'ASC';
return $args;
}
Display only comments from a specific post ID
add_filter('comments_list_table_query_args', 'display_comments_from_specific_post');
function display_comments_from_specific_post($args) {
$args['post_id'] = 42;
return $args;
}