How to sort or bulk delete posts based on the number of words? (11 posts)
Hello, I want to bulk delete all posts that have less than certain number of words in it. I know that we can do this manually, but there are too many posts to be checked one by one.
Is there anyone knows how to do this? I want to delete all the posts that has less than 300 words. Perhaps there is a plugin that can do this?
Or maybe somebody know a plugin that can sort the post based on the number of words? Or at least show the number of words in the Posts page?
Needless to say, you absolutly must backup your database before running any query such as this. Untested, but either way should do the trick.
From PHP –
global $wpdb; $wpdb->prepare('DELETE FROM %1$s WHERE LENGTH('post_content') < 300', $wpdb->posts) $wpdb->query($query);
From MySQL –
WHERE LENGTH('post_content') < 300;
I’ve found the plugin that show the number of words in the Admin’s Posts Edit page. There were two plugins that can do this, the Admin Word Count plugin and Admin Word Count Column plugin.
However, both of them don’t have the sorting ability. They just display the number of words for each post, which means that it would still be a lot of work to get rid all the posts with less than 300 words.
duck_boy: thank you! I’ll try them and let you know the result..
Just a thought – you may want to add on to the end of the query –
AND post_type = 'post'
Doing this will ensure only your posts are deleted, not you pages, media, etc.
I really appreciate your replies. There are some things I want to confirm:
Does your line of command true? So it is
DELETE FROMwp_postsWHERE LENGTH(‘post_content’) < 300;
DELETE FROM wp_posts WHERE LENGTH(‘post_content’) < 300; ?
I also want to know if I should leave the default command or just delete this line below and use yours:
SELECT * FROM
Oh, and one more thing. From my newbie understanding, the command LENGTH will count the character, instead of the words. Is that correct?
I recently google for it and came up with the command below:
DELETE FROM wp_posts WHERE SUM( LENGTH(post_content) – LENGTH(REPLACE(post_content, ‘ ‘, ”))+1) < 300;
However, it didn’t work out and the progr