I’m trying not to show comments from a certain custom post type int the comments list on the admin interface.
I went to the “wp-admin/includes/class-wp-comments-list-table.php” and tried to play with the $args array which is passed into the “get_comments” function in order to feed the comments list table.
If I add a post_type parameter there I can filter the comments in order to only see comments from that post type.
But what I want is the opposite: I would like to see all comments but those from one specific post type.
I tried several things like:
1) create a white list by adding all the post types I need but the one I want to exclude. The problem is that it only shows the first type of the array
$args = array(
...,
'post_type' => array('aaa','bbb','ccc','ddd')
);
2) I tried to create a black list by excluding the post type I need. It just doesn’t consider the filter and shows comments from all post types.
$args = array(
...,
'exclude' => array('post_type'=>'xxx')
);
//OR
$posts_to_exclude=get_posts(array('post_type'=> 'xxx'));
foreach ($posts_to_exclude as $single)
{
$target[] = $single->ID;
};
$args = array(
...,
'posts__not_in' => $target
);
Nothing worked.
I just don’t know what else to do.
What concerns me is that the white list seems to be ok according to what I can read over the internet but for some reason it only shows me the first element of the post_type array (and I’m sure I have comments for all posts as they all show up when I don’t filter the comments list table.
Thank you for your help.
You’ll need to filter
comments_clauses
, sinceWP_Comment_Query
only supports a limitedpost type == X
argument.