不知道有插件,但可以使用wp\\u schedule\\u single\\u event函数。
首先创建一个元框,该框包含以下值:删除时间以及从功能中删除时要设置的类别。
/* hook meta box */
add_action("admin_init", "admin_init");
/* hook meta box function */
function admin_init(){
add_meta_box("Featured Removal", "Featured Removal", "Featured_Removal_options", "post", "normal", "high");
}
/* display meta box */
function Featured_Removal_options() {
global $post;
$custom = get_post_custom($post->ID);
echo \'<input type="hidden" name="wp_meta_box_nonce" value="\', wp_create_nonce(\'Featured Removal\'), \'" />\';
<?
<table border=0>
<tr>
<th style="width:20%"><label for="Remove_after">Remove From Featured After:</label></th>
<td><input type="text" name="Remove_after" id="Remove_after" value="<?php $custom[\'Remove_after\'] ? $custom[\'Remove_after\'] : \'\'; ?>"/><br/>
Enter time in Seconds Ex: 1 Hour = 3600 Seconds , 1 Day = 86400 Seconds.
</td>
</tr>
<tr>
<th style="width:20%"><label for="Remove_after_to_cat">Remove From Featured To Category:</label></th>
<td><input type="text" name="Remove_after_to_cat" id="Remove_after_to_cat" value="<?php $custom[\'Remove_after_to_cat\'] ? $custom[\'Remove_after_to_cat\'] : \'\'; ?>"/><br/>
Enter the category id of the category you want to remove the post after the time has passed. if more then one separate by commas Ex: 12,13,24
</td>
</tr>
</table>
<?php }
/* save meta box hook*/
add_action(\'save_post\', \'save_Featured_Removal_options\');
/* save meta box function*/
function save_Featured_Removal_options($post_id) {
if (!wp_verify_nonce($_POST[\'wp_meta_box_nonce\'], "Featured Removal")) {
return $post_id;
}
// check autosave
if (defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) {
return $post_id;
}
If (isset($_POST[\'Remove_after\']) && isset($_POST[\'Remove_after_to_cat\'])){
//cerate scheduled event
$time = time() + $_POST[\'Remove_after\'];
wp_schedule_single_event($time, \'Clean_my_featured\',$post_id);
//save meta data
update_post_meta($post_id, \'Remove_after\', $_POST[\'Remove_after\']);
update_post_meta($post_id, \'Remove_after_to_cat\', $_POST[\'Remove_after_to_cat\']);
}
}
现在观察save Meta Box函数,如果用户为新类别输入了删除时间和类别id,那么我们将使用
wp_schedule_single_event 并将其挂到“
Clean_my_featured“。
因此,现在我们只需要添加该挂钩的操作和移除本身的函数:
/* hook removal event function */
add_action(\'Clean_my_featured\',\'remove_post_from_featured\');
// the function that removes a post form a category and sets a new one
function remove_post_from_featured($post_id) {
$cats = get_post_meta($post_id, \'Remove_after_to_cat\', true);
wp_set_post_terms( $post_ID, $cats, \'category\');
}
我不知道这是否有效,但它应该将所有内容复制到插件文件或主题函数中。php文件,它应该可以工作。
如果不让我知道。