如果我理解正确,您想使用自己的选择表单来更新帖子的发布状态,而不是发布/取消发布按钮?像这样的东西可以做到这一点:
function save_my_data($post_id){
if($_POST[\'publish\'] == \'yes\' && get_post_status($post_id) != \'publish\'){ //whatever your post variable is
remove_action(\'save_post\', \'save_my_data\'); //if you don\'t unhook the function you\'ll have an infinite loop
wp_publish_post($post_id);
add_action(\'save_post\', \'save_my_data\'); //rehook the function
}
if($_POST[\'publish\']) == \'no\' && get_post_status($post_id) == \'publish\'){
remove_action(\'save_post\', \'save_my_data\'); //if you don\'t unhook the function you\'ll have an infinite loop
wp_update_post(array(
\'ID\' => $post_id,
\'post_status\' => \'draft\'
));
add_action(\'save_post\', \'save_my_data\'); //rehook the function
}
}
您可能希望添加一些错误处理并对其进行一些优化。您可能还需要说明此处列出的其他帖子状态:
http://codex.wordpress.org/Post_Status#Default_Statuses