Skip Navigation

[Resolved] Limit to create custom post by user

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 1 voice.

Last updated by David Gimenez 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1109575

Hi there.

I'm trying to do the same that Bead wrote in this post: https://toolset.com/forums/topic/limit-the-number-of-posts-submitted-by-registered-customers/#post-368894

My custom post type is

Name plural: Negocis
Name singular: Negoci
Slug: negoci

The role user allowed to create is -> Gratuit

I have in my function.php this:

/**
*Count posts of given type, so each user can create post only [desired number of posts] posts
*/
function u_post_count() {

//we create a $variable that holds the value of posts of this user
//we use the count() function <u>hidden link</u>
//we use a get_posts to get the posts of given type, and get_current_user_id() to get the current logged in user
//https://codex.wordpress.org/Template_Tags/get_posts
//https://codex.wordpress.org/Function_Reference/get_current_user_id

//we create the $variable
$user_post_count = count( get_posts( array( //we get the posts

//we define the Post type
'post_type' => 'negoci',

//we get the current logged in author
'author' => get_current_user_id(),
) ) );

//We return the amount of posts created by user
return $user_post_count;
}

ANd this in the page:

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'Gratuit' ) AND ( u_post_count() lt '1' )"]
<b>Això és pel condicional</b>
[/wpv-conditional]

I didn't create any custom post with my user with role Gratuit

But this doesn't show anything. Any idea about what'm I'm doing wrong? Thanks!

#1109603

Solved. Thanks!