Allow users to only CREATE one single (custom) post

I created a custom post type with taxonomy and now want to allow users (of a specific user group) to post only one single post in a specific category.

If the user has already posted a post, he can only edit his own post (I already have the PHP for that).

I found a lot of solutions that users can only post in a specific category or only edit their own posts, but no-where an conditional that the user can only post one post.

The functionality might be seen as a "second profile", it should be like a profile (Users can post one post, edit this post, all users and guests can view the post).

I would have several ideas, maybe a conditional, if the user has 0 posts in the category, than he has the right to post?

Topic content-restriction conditional-content Wordpress

Category Web


You can use WP_Query to get the posts created by user in a specific category as well as a post type.

To find posts of a specific category you can use the following snippet:

$query = new WP_Query( 'category_name=staff' );

Where as to find posts of an author you can use the following snippet:

$query = new WP_Query( 'author=123' );

Combine this in a single query and if the any posts are returned that means user has already created a post.

For reference, check this link

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.