0

I searched a lot about this, found plugins that are out dated and consumes massive resources and finally do nothing, is there like an SQL line to delete all posts that have a word count like less than 100 words?

Thanks,

  • Counting words with SQL isn't so easy. The problem is that it's pretty hard to define what a word is, so that MySQL can understand it. For example there are special strings that are spaces ( ) and can be used as word separators... Also you can have HTML tags inside your content - how should that be counted? – Krzysiek Dróżdż Nov 19 '18 at 7:53
  • may be character length? in average the word is 5 characters or so, so can we delete using sql posts with length below 500 or 600 characters (inculding spaces for example)? – Abdelrahman Ellithy Nov 19 '18 at 15:32
0
function delete_posts() {
$lastposts = get_posts(array('numberposts' => -1));

if ( $lastposts ) {
    foreach ( $lastposts as $post ) :
        setup_postdata( $post ); ?>        
        <?php
        $content = get_the_content();
        if (str_word_count($content) < 100) {   
            wp_trash_post($post->ID);
        }

        ?>
        <?php
    endforeach; 
    wp_reset_postdata();
}}add_action( 'init', 'delete_posts' );
  • this caused fatal error Fatal error: Allowed memory size exhausted (tried to allocate 84 bytes) /.../wp-includes/wp-db.php on line 1889 – Abdelrahman Ellithy Nov 19 '18 at 15:24
  • Two way - 1. Use below code into wp-config.php file define('WP_MEMORY_LIMIT', '256M'); 2. Edit your PHP.ini file memory_limit = 256M; – Parth Shah Nov 20 '18 at 11:11
  • but this i think will cause server to crash, I had a load surge even at the previous limit! – Abdelrahman Ellithy Nov 20 '18 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.