The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →To display your most commented posts, sort a WordPress post query by comment_count in descending order. A custom WP_Query gives the most control; a Query Loop can work in block themes when the installed editor exposes comment-count ordering; and the Display Posts Shortcode plugin offers a no-PHP alternative.
“Most commented” normally means the posts with the highest lifetime comment totals. It does not mean the posts receiving the most comments this week or month unless you add a separate date-based rule.
Choose the implementation that fits your site
| Method | Best for | Control | Maintenance |
|---|---|---|---|
Custom WP_Query |
Developers and site maintainers | Explicit sorting, limits, post types and comment thresholds | Requires theme or plugin code maintenance |
| Query Loop and blocks | Block themes and editor-managed layouts | Depends on the query controls available in the installed WordPress version | Least custom code when the required controls are present |
| Display Posts Shortcode | Sites that need a shortcode instead of PHP | Limited to the shortcode’s supported parameters | Depends on current plugin maintenance and compatibility |
Method 1: Build a custom query with WP_Query
Use this approach when you need predictable output, a specific location such as a sidebar, or a minimum-comment threshold.
Basic most-commented query
Add the query to a custom plugin or an appropriate theme template rather than editing WordPress core files:
<?php
$most_commented = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'comment_count',
'order' => 'DESC',
)
);
if ( $most_commented->have_posts() ) :
echo '<ol class="most-commented-posts">';
while ( $most_commented->have_posts() ) :
$most_commented->the_post();
echo '<li>';
printf(
'<a href="%s">%s</a> <span>(%d comments)</span>',
esc_url( get_permalink() ),
esc_html( get_the_title() ),
(int) get_comments_number()
);
echo '</li>';
endwhile;
echo '</ol>';
endif;
wp_reset_postdata();
?>
What each argument does
post_status => 'publish'excludes drafts and other non-public posts.post_type => 'post'limits the list to regular blog posts. Change it to a registered custom post type when appropriate.posts_per_pagesets the number of results.orderby => 'comment_count'sorts by each post’s total comment count.order => 'DESC'places the largest totals first.
The query ranks by the count WordPress uses for the post. It does not create a rolling popularity period or distinguish when comments were submitted.
Require a minimum number of comments
You can exclude posts with little or no discussion by supplying comment_count as a query filter. For example, this requests published posts with at least 25 comments:
Rank #2
<?php
$most_commented = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'comment_count',
'order' => 'DESC',
'comment_count' => array(
'value' => 25,
'compare' => '>=',
),
)
);
?>
The same argument can represent an exact count with an integer, or a comparison such as >=. Use the comparison form when the goal is a threshold rather than an exact total.
Render the secondary loop safely
If this query runs inside a template that already has a main WordPress loop, call wp_reset_postdata() after rendering it. That restores the global post so following template tags refer to the page being displayed. Set an explicit post type if the list should include or exclude custom post types.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Method 2: Use a Query Loop in the block editor
A Query Loop can provide the list and its layout without writing PHP. In the Query Loop’s query controls, look for an ordering option based on comment count and select descending order. WordPress versions and editor configurations do not all expose identical controls, so confirm that option exists on the site before promising a completely code-free ranking.
Show the count beside each title
Inside the Query Loop’s Post Template, insert the Comments Count block. It displays the total number of comments for the current post. On a non-singular page, that block needs the post context supplied by the Post Template; placing it outside the loop will not produce the count for each result.
Rank #4
When this route is a good fit
- Use it for block-theme sidebars, home-page sections and archive layouts managed in the Site Editor.
- Prefer the custom query when you need a minimum count, a custom post type, or query arguments the editor does not expose.
Method 3: Use the Display Posts Shortcode plugin
The Display Posts Shortcode plugin documents this pattern for ordering a list by comment count:
[display-posts orderby="comment_count" order="DESC" posts_per_page="5"]
Place the shortcode in a Shortcode block, widget area or other location where your site permits shortcodes. Check the plugin’s current maintenance status, WordPress compatibility and supported parameters in its current listing before installing it. A shortcode removes custom PHP from the page, but it adds a plugin dependency and gives you only the controls that the plugin implements.
Best Value
Most-commented posts versus latest comments
These features answer different questions:
- Most-commented posts: a ranked list of posts ordered by each post’s total comment count.
- Latest Comments block: a feed of individual recent comments, their authors and associated posts.
- Comments Count block: the number of comments for the current post context; it does not rank a collection of posts by itself.
Use the Latest Comments block when recency matters. Use a comment-count-sorted query or Query Loop when you want posts with the largest discussion totals.
Practical display and quality checks
- Choose a finite result count so a sidebar or home-page section remains compact.
- Escape generated titles and URLs, as in the PHP example.
- Decide whether closed comments, pending comments or custom post types should be represented according to the site’s content model.
- Label the number clearly, such as “42 comments,” and make the post title the primary link.
- Test the layout with long titles, zero-comment results and tied comment totals. The documented ordering does not define a special tie-breaking policy, so do not promise a particular order among posts with equal counts.
Troubleshooting
The list is empty
Confirm that matching posts are published, that the selected post type is correct, and that a minimum-comment filter is not higher than every post’s count.
The count appears but posts are not ranked
Showing a Comments Count block only prints each current post’s total. The surrounding Query Loop or WP_Query must perform the ordering.
The list changes unexpectedly after adding comments
That is expected for a lifetime-total ranking: a new approved comment can move a post upward. A weekly or monthly ranking requires a separate date-window query rather than comment_count alone.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

