All comments are just listed under "Comments" there is no attribute or parameter which creates a seperate "Comments" section/page for your custom post-type. Atleast not that I know of.
However, you could add a filter to the comments list, to filter all comments based on post-types.
It will be just like a category filter in the post list.
So you can create a HTML select field
, which contains an option for every custom post-type
. The value
of each option needs to be the slug of the post-type
. The select
element needs a name of "post_type"
to make the filtering work.
/**
* Create custom comments filter for post types
**/
function my_comments_filter() {
// we are only getting the none-default post types here (no post, no page, no attachment)
// you can also change this, just take a look at the get_post_types() function
$args = array(
'public' => true,
'_builtin' => false
);
$post_types = get_post_types( $args, 'objects' ); // we get the post types as objects
if ($post_types) { // only start if there are custom post types
// make sure the name of the select field is called "post_type"
echo '<select name="post_type" id="filter-by-post-type">';
// I also add an empty option to reset the filtering and show all comments of all post-types
echo '<option value="">'.__('All post types', 'my-textdomain').'</option>';
// for each post-type that is found, we will create a new <option>
foreach ($post_types as $post_type) {
$label = $post_type->label; // get the label of the post-type
$name = $post_type->name; // get the name(slug) of the post-type
// value of the optionsfield is the name(slug) of the post-type
echo '<option value="'.$name.'">'.$label.'</option>';
}
echo '</select>';
}
}
// we add our action to the 'restrict_manage_comments' hook so that our new select field get listet at the comments page
add_action( 'restrict_manage_comments', 'my_comments_filter' );
If you add this code to your functions.php
, or better, to a plugin
, you will see a new filter on the top of the comments backend. Here you can select a custom post-type
and than click on Filter
, to filter the comments. If you select "All post types" and click filter again, all comments should show.