有时候,我们需要连续发布同一个分类下的文章,每篇文章都要重新选择分类非常麻烦。下面,我们就用程序来搞定这个问题。
add_action('publish_post', 'save_fl' );
add_action('admin_footer-post.php', 'choose_a_category_before_publish');
add_action('admin_footer-post-new.php', 'choose_a_category_before_publish');
function save_fl($post_id)
{
if ( wp_is_post_revision( $post_id ) )
return;
global $current_user;
update_option( 'default_fl_' . $current_user->ID , json_encode($_POST['post_category']) );
get_option('default_fl_' . $current_user->ID);
}
function choose_a_category_before_publish(){
global $post_type;
global $current_user;
$post_categorys = json_decode(get_option('default_fl_' . $current_user->ID), TRUE);
if($post_type=='post'){
?>
<script>
jQuery(function($){
<?
if(count($post_categorys) > 0)
foreach($post_categorys as $post_category)
{?>
$("#in-category-<? echo $post_category; ?>").attr("checked","checked");
<?}
?>
});
</script><?
}
}