Skip Navigation

[Resolved] I am trying to limit the number of posts the user can submit per post type

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to limit the number of posts an author can create in one specific post type. I'm using WPML, so the posts are translatable.

Solution: Use the following custom code to determine the number of posts:

function my_u_post_content() {
$my_u_post_content = count( get_posts( array(
'post_type' => 'local-user-profile',
'author' => get_current_user_id(),
'numberposts' => -1,
) ) );
return $my_u_post_content;
}

You can use this function in a conditional by registering it in Toolset > Settings > Functions in side conditional evaluations

This support ticket is created 5 years, 7 months 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1233875

I am trying to: limit the number of posts the user can submit in a certain Post Type called local-user-profile

I inserted the below code in functions php, and the functions does not work
We run wpml as well.
Although I have three posts the function return 5, the same result even if I have only two posts in that specific PT
Please advice, thx
We also tried using the solutions at this link: https://toolset.com/forums/topic/limit-the-number-of-posts-submitted-by-registered-customers-ii/ and this link https://toolset.com/forums/topic/i-need-help-with-limitting-posts-from-a-user-role/

/**
* New custom code snippet.
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );
function my_u_post_content() {
$my_u_post_content = count( get_posts( array(
'post_type' => 'local-user-profile',
'author' => get_current_user_id(),
) ) );
return $my_u_post_content;
}

#1233981

Hi, please go to WPML > Settings > Multilingual Content Setup tab, and scroll down to Post Type Translation. What setting is selected for the local-user-profile post type?
Now log in as the User who is author of only 2 local-user-profile posts. Check both posts and tell me the translation status of each post, in each language.

#1234353

Hi Christian, the setting in wpml is Translatable - only show translated items, english version with the slug local-user-profile
Both posts are duplicated from Romanian to English and German , thx

#1234720

Okay to get the total number of posts, you must modify this code slightly:

function my_u_post_content() {
$my_u_post_content = count( get_posts( array(
'post_type' => 'local-user-profile',
'author' => get_current_user_id(),
'numberposts' => -1,
) ) );
return $my_u_post_content;
}

Otherwise the number of posts returned will be limited by the standard pagination of your blog posts.

My guess is that the function will return "6" now, since it's two posts duplicated twice ( 2 + 2 + 2 ). You must take these duplicate posts into account when calculating number of posts per author.

#1241736

My issue is resolved now. Thank you!