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 > 99){
wp_die(‘发布上限为:99。’);
}
}
}
});
使用上面这段代码之后,再点击新增,就会出现:提示比如我只允许发布1篇
add_action(‘current_screen’, function($current_screen){
global $pagenow;
if($pagenow == ‘post-new.php’){
$post_type = $current_screen->post_type;
if($post_type == ‘post’){ // 这里可以改成你需要限制的日志类型
//$counts = wp_count_posts($post_type);
$counts = count_user_posts($user_id);
$total = array_sum((array)$counts);
if($total > 1){
wp_die(‘发布上限为:1。’);
}
}
}
});