如果你和我一样,使用 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。');
}
}
}
});
使用上面这段代码之后,再点击新增商品,就会出现:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有