#65392 closed defect (bug) (fixed)
"Show more comments" button in comments metabox doesn't load new comments if they are of a type different than 'comment'
| Reported by: | aljullu | Owned by: | tyxla |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | Comments | Version: | trunk |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: | administration |
Description
When comments have a custom type (ie, review) the 'Load more comments' button in the comments metabox in the editor doesn't work properly: it duplicates the existing comments listed instead of loading the remaining ones.
Steps to reproduce (custom code)
- Add this code snippet somewhere in your page. tl;dr, it creates a custom post type and makes its comments have the
cpt_responsetype:
<?php add_action( 'init', function () { register_post_type( 'my_cpt', array( 'labels' => array( 'name' => 'My custom CPT entries', 'singular_name' => 'My custom CPT entry', 'add_new' => 'Add entry', 'add_new_item' => 'Add new entry', ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_rest' => true, 'supports' => array( 'title', 'comments' ), 'menu_icon' => 'dashicons-testimonial', 'has_archive' => false, ) ); }, 0 ); add_filter( 'preprocess_comment', function ( $data ) { $post_id = isset( $data['comment_post_ID'] ) ? (int) $data['comment_post_ID'] : 0; if ( $post_id && 'my_cpt' === get_post_type( $post_id ) ) { $data['comment_type'] = 'cpt_response'; } return $data; }, 1 );
- In wp-admin, go to My custom CPT entries > Add new entry.
- Add a title and publish.
- In the frontend, add at least 21 comments to that entry.
- Back in the editor, verify the comments metabox shows comments 21-12 (they are ssorted by recency).
- Click on Show more comments.
- Notice comments 21-12 are loaded again, appearing repeated.
Expected behavior: comments 11-2 should be loaded, instead.
Steps to reproduce (WooCommerce)
The same can be reproduced in WooCommerce.
- Create a product.
- In the frontend, add 21 reviews.
- In the product editor, verify the reviews metabox shows reviews 21-12.
- Click on Show more comments.
- Notice comments 21-12 are loaded again, appearing repeated.
Explanation
The current logic to load new comments in the comment's metabox in the editor assumes the HTML elements will have the comment class, but that's only the case for comments of type comment. If comments have a different type, like review, they won't be counted and the button will fail to work.
Change History (9)
This ticket was mentioned in PR #12055 on WordPress/wordpress-develop by @aljullu.
7 weeks ago
#1
- Keywords has-patch added
@aljullu commented on PR #12055:
7 weeks ago
#2
There are some PHPUnit Tests automations failing, but they don't seem related.
This ticket was mentioned in Slack in #core by abdullahramzan. View the logs.
6 weeks ago
#5
@
5 weeks ago
- Keywords 2nd-opinion dev-feedback needs-testing removed
Tested this ticket on WordPress Playground.
Created a test entry and added 44 comments. Verified the Comments metabox in the editor.
After clicking "Show more comments", older comments loaded correctly instead of repeating the previously displayed comments.
Confirmed:
- No duplicate comments appeared.
- Comment pagination works as expected.
- The issue described in the ticket is resolved.
Patch tested successfully. ✅
@tyxla commented on PR #12055:
2 weeks ago
#6
There are some PHPUnit Tests automations failing, but they don't seem related.
Yep. Rerunning while I'm taking a look and testing.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Right now, the comments metabox in WordPress assumes all comments
<tr>elements will have thecommentclass. But that's not true if the comment type is custom, like WooCommerce's reviews.This PR makes the selector match the
<tr>elements by their id starting withcomment-, this seems to be a safer approach because it matches regular comments and other comment types like reviews.It also changes the default number of reviews which are requested in the AJAX call. Until now, it was
20, but the backend was falling back to `10`, causing an inconsistency that made the frontend think all comments were already loaded even if they weren't.Trac ticket: [](https://core.trac.wordpress.org/ticket/65392)
Initial report in WooCommerce repo: https://github.com/woocommerce/woocommerce/issues/52731.
## Use of AI Tools
AI assistance: Yes
Tool(s): Cursor
Model(s): Composer
Used for: Researching the code, brainstorming solutions and writing steps to reproduce.
## Steps to reproduce (custom code)
{{{PHP
add_action( 'init', function () {
}, 0 );
add_filter( 'preprocess_comment', function ( $data ) {
}, 1 );
}}}
## Steps to reproduce (WooCommerce)