I have lots of useless approved comments on my site. One way I use of removing them is
DELETE FROM wp_comments WHERE comment_content LIKE '%agree%with%you,%thanks%, '
However, this is removing good comments as well and leaving out a lot of bad comments.
How Do I modify the query to delete comments with less that 5 words.
Due to the large number of comments in the actual database, I am worried whether to run a command with like
since it will scan more than 20K rows. Is there any way to reduce the load ?
try using
LENGTH
. bellow you will delete entries which have less then 35 characters. Ithink its better then using words.like that:
DEMO HERE
You can try counting the characters, replace all the spaces with empty
''
and subtracting them. You’ll needCHAR_LENGTH()
andREPLACE
.The plus 1 is an adjustment since you’ll have 1 less space than words.
Note:
CHAR_LENGTH()
for mysql, you could useLENGTH()
for others.E.g.:
You can try using regular expressions, something like that:
The most effective way is:
MySQL Query Start:
-- Select All Rows
-- Check Space Count
-- Delete Those Records who Has less than 5 words
-- Select All Rows Again to Verify Rows
In your case you can use like this:
-- Live DEMO
Click Here to see Live DEMO