Assuming your theme’s templates use get_comments(), you can alter the query used by this function to exclude comments with a certain meta value. One good way to do this is to create a child theme, then alter how get_comments() is called by adding appropriate meta query arguments.
Another way is to alter the query vars created by get_comments() by hooking the ‘pre_get_comments’ action. The WP_Comment_Query object is passed to your callback by reference so anything you change in the object directly affects the query used by get_comments().
Another approach also starts with a child theme. The comments are queried as usual. Around the loop that outputs the comment, place a conditional that checks for the comment meta value before doing the output. If the meta exists, don’t output the comment, just continue with the next comment. This is less efficient because you are getting comments that will never be output. You may find this approach easier to code though. If all things are otherwise equal, I recommend you use one of the first two approaches.
Thread Starter
umchal
(@umchal)
Actually I have found the parse_comment_query filter and could add the meta_query argument to exclude items with certain meta keys.
Thanks for your input though.
(@umchal)
9 years, 10 months ago
Hi there,
I’m looking for a way not to display certain comments which have a specific comment meta and could not find relevant information on the web. What would be the best way to achieve it?
The filter
comment_textallows us to remove/modify comment text but not to completely remove the comment container element.Thanks in advance.