function delete_poor_posts($post_type = 'post', $min_words = 20, $letters_x_word = 5){
$posts = get_posts(array(
'post_type' => $post_type,
'fields' => 'ids',
'meta_query' => array(
array(
'key' => 'is_poor',
'compare' => 'NOT EXISTS'
),
),
'posts_per_page' => -1
));
ini_set('max_execution_time', 0);
foreach ($posts as $post_id) {
$content_post = get_post($post_id);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = explode(" ", strip_tags( $content ));
$itsOK = 0;
foreach ($content as $text) {
if(strlen($text) >= $letters_x_word)$itsOK++;
}
if($itsOK < $min_words){
wp_delete_post( $post_id, true );
}else{
update_post_meta($post_id, 'is_poor', 'no');
}
}
die('fin');
}
if((current_user_can('editor') || current_user_can('administrator')) && isset($_GET['delete']) && $_GET['delete'] == 'now'){
delete_poor_posts();
}