Skip to content

Fix 'Show more comments' button in comments metabox not working for custom comment types#12055

Open
Aljullu wants to merge 1 commit into
WordPress:trunkfrom
Aljullu:fix/65392-show-more-comments-custom-comment-type
Open

Fix 'Show more comments' button in comments metabox not working for custom comment types#12055
Aljullu wants to merge 1 commit into
WordPress:trunkfrom
Aljullu:fix/65392-show-more-comments-custom-comment-type

Conversation

@Aljullu
Copy link
Copy Markdown

@Aljullu Aljullu commented Jun 2, 2026

Right now, the comments metabox in WordPress assumes all comments <tr> elements will have the comment class. 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 with comment-, 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: woocommerce/woocommerce#52731.

Also kudos to @PavloBorysenko for the initial research in woocommerce/woocommerce#52731 (comment).

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)

  1. Add this code snippet somewhere in your page. tl;dr, it creates a custom post type and makes its comments have the cpt_response type:
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 );
  1. In wp-admin, go to My custom CPT entries > Add new entry.
  2. Add a title and publish.
  3. In the frontend, add at least 21 comments to that entry.
  4. Back in the editor, verify the comments metabox shows comments 21-12 (they are ssorted by recency).
  5. Click on Show more comments.
  6. Verify comments 11-2 are loaded (before this fix, comments 21-12 were loaded again).
  7. Press Show more comments again and verify comment 1 is loaded (before this fix, the button would not be visible).

Steps to reproduce (WooCommerce)

  1. Create a product.
  2. In the frontend, add 21 reviews.
  3. In the product editor, verify the reviews metabox shows reviews 21-12.
  4. Click on Show more comments.
  5. Verify reviews 11-2 are loaded.
  6. Press Show more comments again and verify review 1 is loaded.

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@Aljullu Aljullu marked this pull request as ready for review June 2, 2026 14:24
@Aljullu
Copy link
Copy Markdown
Author

Aljullu commented Jun 2, 2026

There are some PHPUnit Tests automations failing, but they don't seem related.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aljullu.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant