Skip to content

Instantly share code, notes, and snippets.

@halles
Created January 17, 2012 18:14
Show Gist options
  • Save halles/1627917 to your computer and use it in GitHub Desktop.
Save halles/1627917 to your computer and use it in GitHub Desktop.
WordPress: Script for deleting several posts based on some conditions. (Author: Gurthg @ irc.feenode.net #wordpress)
<?php
add_action( 'admin_init', 'iworks_dtl' );
function iworks_dtl(){
global $wpdb;
$query = 'SELECT ID FROM '.$wpdb->posts.' WHERE LENGTH(post_content) < 800 AND post_type = "post" AND post_status = "publish"';
$data = $wpdb->get_results( $query );
foreach( $data as $one ) {
wp_delete_post( $one->ID, true );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment