简体   繁体   English

限制Wordpress中的帖子数量

[英]Limit the Number of Posts in Wordpress

I'd like to limit the number of posts of a custom post type to a maximum (eg 5 posts), regardless of the users. 我想将自定义帖子类型的帖子数量限制为最大(例如5个帖子),无论用户是谁。 For example, say i have my custom post type named CUSTOMPOSTS, if there are 5 of these posts, nobody should be able to create new ones (without first deleting one of the others). 例如,假设我有一个名为CUSTOMPOSTS的自定义帖子类型,如果这些帖子中有5个,则任何人都不能创建新帖子(无需先删除其他帖子)。

Can it be done? 能做到吗

Kind regards! 亲切的问候!

There are multiple ways of doing it. 有多种实现方法。 But the easiest is to hook into wp_insert_post and prevent it from working. 但最简单的方法是挂接到wp_insert_post并阻止其工作。 You could force every new post to draft until they delete/unpublish an older one and when they do you can allow them to publish new one. 您可以强迫每个新帖子draft直到他们删除/取消发布较旧的帖子为止,并且当他们这样做时,您可以允许他们发布新的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM