I've tried the plugins that are available in the Wordpress plugins section but they seem to fail miserably. Initially, I used Auto Post Expire By User Role which worked for a time, but for some reason now it doesn't.
What I want is to add a code in functions.php that will automatically set as drafts posts which are 30 days older than their published date.
I have the following code but don't know if this is the one that I should be using. Is this correct and if not, what is the correct form?
function expire_posts() { global $wpdb; $daystogo = "30"; $sql = "UPDATE wp_posts SET `post_status` = 'draft' WHERE `post_type` = 'post' AND DATEDIFF(NOW(), `post_date`) > '$daystogo')"; } add_action('wp_head', 'expire_posts');