admin管理员组

文章数量:1290052

The picture gives an illustration of the pending comments I am referring to. As you can see, the number shown on the menu bar is different from the number shown on the pending column.

I am trying to find a way to edit the numbers highlighted in yellow

The picture gives an illustration of the pending comments I am referring to. As you can see, the number shown on the menu bar is different from the number shown on the pending column.

I am trying to find a way to edit the numbers highlighted in yellow

Share Improve this question edited Jul 3, 2021 at 16:58 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jul 3, 2021 at 15:41 Fabian AmranFabian Amran 2693 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can manually adjust this number using the following method.

function adjust_wp_comments_count( $original_counts ) {
    $counts = new \stdClass();
    $counts->moderated = 99;
    return $counts;
}
add_filter( 'wp_count_comments', 'adjust_wp_comments_count', 100, 1 );

The line: $counts->moderated = 99 is what you will need to adjust if you want to set it to a particular value or calculation of your choosing.

Note: I've set the filter priority to 100 as I found other plugins also affect this. It depends on your setup. If you add this filter and it doesn't work, change 100 to 100000 or any other large number. The higher the number, the more likely that your modifications will take effect.

WordPress also dynamically changes the comment counts on-the-fly as you change comment status in the Edit Comments page. This code doesn't take any of that into consideration. It simply provides you a mechanism to set the number as it's displayed when the page loads.

Note: Forcefully setting this value may have unintended consequences elsewhere in the system. Test and evaluate for your particular circumstances.

本文标签: Which hook do I use to edit pending comment count on wordpress dashboard