| |||||||||||||
|
| Wordpress Plugin: Delete, state or move expired postsI was search for a plugin that can let expire posts in Wordpress and found this wonderfull plugin: Astros Wordpress Plugin. It's really a good idea and it's a good implementation as well. Unfortunatly it wasn't exactly what I needed, because it deleted expired posts irreversibly. But I wanted to be able to set a post to "draft" or to move it to a special category if it had expired. So I extended the plugin. Have fun. Download Plugin. How to use?Have a look at the file atropos.php in the zip-folder. At line 23 you will find:
function atropos_delete_expired_posts () {
global $wpdb;
$result = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_atropos_expiration_date' AND meta_value < '" . date("Y/m/d") . "'");
foreach ($result as $a) {
// Delete post if post is expired
/* wp_delete_post ($a->post_id);
*/
// Set new post_status if post is expired
/*$my_post = wp_get_single_post($a->post_id, ARRAY_A);
$my_post['post_status'] = 'pending'; // draft
wp_insert_post($my_post);
*/
// Move expired posts to category "expired"
/*$my_post = wp_get_single_post($a->post_id, ARRAY_A);
$my_cat = get_category_by_slug("expired");
$my_post['post_category'] = array((int)$my_cat->term_id);
wp_insert_post($my_post);
*/
}
}
See the 3 blocks which are commented out?
TippsThe expire-script now does not only run at midnight, but when you activate the plugin as well. So if you want to test the plugin, just deactivate and activate the plugin again. If you have still problems testing it, uncomment the last line - it will trigger the expire-script EVERYTIME a page of your site is browsed. Futher improvementsI think the server-load is not too much to let the script run hourly. For this the form has to be extended to set the expiration-hour as well, and the database has to be extended to store the hour. What do you want for that?Well, I spend some time on it, so if you use it on your wordpress-site, you might consider to set a link to the original author and to this site to credit the work.
| ||||||||||||
|
| |||||||||||||