conditional content - Allow users to only CREATE one single (custom) post

admin2025-01-08  4

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?

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?

Share Improve this question edited Sep 30, 2014 at 6:57 kaiser 50.8k27 gold badges150 silver badges244 bronze badges asked Sep 11, 2014 at 18:26 Jobo21Jobo21 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266999a1167.html

最新回复(0)