5ucms论坛

标题: wordpress自动选择上一篇文章选择的分类目录 [打印本页]

作者: admin    时间: 2021-5-29 18:28
标题: wordpress自动选择上一篇文章选择的分类目录
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><?
    }
}




欢迎光临 5ucms论坛 (http://bbs.5ucms.com/) Powered by Discuz! X3.2