Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-29
3
Medium Priority
?
188 Views
Last Modified: 2014-09-19
On wordpress 3.8

on comments table

What sql query will delete all comments shorter than 50 characters  



P.S.

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

Soo, Lots of points for an sql guy
0
Comment
Question by:Matt_Walker01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 39820644
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) {
        $wpdb->delete('wp-posts',
		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.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39820926
Use this:
delete from comments_table where length(comments_field)<50

Open in new window

0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 39820976
@Zberteoc

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.

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_length
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question