Limit a User to Only Create One Custom Post Type Post

Viewed 5101

I have a custom post type for service providers. Which is essentially a bio page for them. I have it set that they can only edit their own bio page, however to do this I had to grant them the ability to create their own bio page (Add New). Is there a way to remove the "Add New" ability once they have created their own page?

3 Answers
function post_published_limit() {
    $max_posts = 3; // change this or set it as an option that you can retrieve.
    $author = $post->post_author; // Post author ID.

    $count = count_user_posts( $author, 'CUSTOMPOSTTYPE'); // get author post count

    if ( $count > $max_posts ) {
        // count too high, let's set it to draft.

        $post = array('post_status' => 'draft');
        wp_update_post( $post );
    }
}
add_action( 'publish_CUSTOMPOSTTYPE', 'post_published_limit' );

Hope this is your answer. Accept it if this your answer.

Related