• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

wordpress - sql query - comments table - delete all comments shorter that 50 characters

On wordpress 3.8

on comments table

What sql query will delete all comments shorter than 50 characters  


I have 10 questions, highest point level - open about sql queries

Soo, Lots of points for an sql guy
1 Solution
Tom BeckCommented:
Something like this would do it.
$comments = $wpdb->get_results("SELECT * FROM wp_comments WHERE comment_approved=1");
foreach ($comments as $comment) {
    if (strlen($comment->content) < 50) {
		array('comment_ID' => $comment->comment_ID)

Open in new window

If you are wondering why your questions are being neglected I can offer a possibility. While there are some experts who collect points for sport on EE, most are genuinely interested in helping people with real world programming problems. The points are just recognition of their assistance. Your ten questions tend come off as a goof rather than real world problems. Why, for example, would anyone want to delete any comment shorter than 50 characters? Or why would anyone want to replace certain words in comments with random words? That's just messing with the data. It almost sounds malicious, like you're developing some malware to mangle WordPress sites.
Use this:
delete from comments_table where length(comments_field)<50

Open in new window


you have to be careful with the length function in MySQL because depending on the character type a character may count more than 1 byte.

length() function measures in bytes
char_length() function measures in characters.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now