Solved

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

Posted on 2014-01-29
3
178 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 500 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 26

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 57
Mysql sync between 3-4 mysql db 4 25
Advice in Xamarin 21 57
Capture logon name 13 48
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now