[wp-trac] [WordPress Trac] #46243: WordPress Comments Core Query
WordPress Trac
noreply at wordpress.org
Fri Mar 26 16:16:24 UTC 2021
#46243: WordPress Comments Core Query
--------------------------+------------------------------
Reporter: Uranbold | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 5.0.3
Severity: normal | Resolution:
Keywords: dev-feedback | Focuses:
--------------------------+------------------------------
Comment (by donmhico):
@Uranbold regarding to hooking into `wp_count_comments` to prevent the SQL
query from running, you can just use something like this.
{{{#!php
<?php
function bypass_count_comments_sql( $post_id ) {
return (object) array(
'approved' => 0,
'moderated' => 0,
'spam' => 0,
'trash' => 0,
'post-trashed' => 0,
'total_comments' => 0,
'all' => 0,
);
}
add_filter( 'wp_count_comments', 'bypass_count_comments_sql' );
}}}
If you look here - https://core.trac.wordpress.org/browser/tags/5.7/src
/wp-includes/comment.php#L1434 - the code above will `return $filtered;`
preventing `get_comment_count( $post_id );` which invokes the query.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46243#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list