Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-29
3
Medium Priority
?
189 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
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

926 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