WordPress技巧限制文章数量教程

如果你和我一样,使用WordPress MU做一个平台,需要限制每个博客的商品数量:

add_action('current_screen', function($current_screen){
    global $pagenow;
 
    if($pagenow == 'post-new.php'){
        $post_type  = $current_screen->post_type;
 
        if($post_type == 'product'){    // 这里可以改成你需要限制的日志类型
            $counts = wp_count_posts($post_type);
            $total  = array_sum((array)$counts);
 
            if($total > 500){
                wp_die('商品上限为:500。');
            }
        }
    }
});


相关文章