Prevent WordPress from loading comments

I’m displaying the comments for a post my way, using $comm = get_comments() and then passing $comm to wp_list_comments() (this is the reason why).

How to disable WordPress from loading comments from the database into $wp_query, when the comment template is being displayed ? I’m asking this because I want to avoid this extra database call, since I’m getting the comments myself using the above method.

Read More

PS: I also noticed the $comments global variable is a array containing ALL the comments for a post, not just the ones from the current comment page. If I have a post with 10K comments, WP will load all these at once? Seems ridiculous…

Related posts

Leave a Reply

1 comment

  1. You can’t prevent comments_template() from making an SQL query. Well, you could maybe hook into the DB layer to prevent just that specific query, but that would be very cumbersome to do. If this is for a theme, you could just remove the call to comments_template() and replace it with your own function. comments_template() doesn’t do that much: just load all the comments, maybe also the just-submitted comment if it isn’t approved yet, separate them into pings, trackbacks and regular comments if needed, and load the comments template file. Comments paging is relatively young in WordPress, so it’s probably not as efficient as it could be yet.