Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Limit the number of the posts WordPress

  • SOLVED

Hi,

I've a problem for a website realized with wordpress: I would limit the number of the posts of the users.

My idea is that each user (editor) has the possibility at the beginning to insert a limit number of post. After that they have finished them, they have to contact the admin and request a number of posts that they want to write. The admin enables for a specific user the number of post and so on...

Can someone help me?

Answers (6)

2011-02-21

Denzel Chia answers:

Hi,

What you need is a job post for a custom plugin.
A simple script will not meet your requirement.

What you need is a plugin that has an admin option page to assign or reset the number of post allowed per user. A function to remove the number of post allowed when the user posted and to prevent the user from posting when the allowed posts are used up. You probably need some kind of notice for the user to contact admin, when the number of post allowed is used up.

If you want to hire me, my current rate is $30 per hour. I estimate it will take at least 3 hours to code and test the plugin.

Thanks.
Denzel


giorgioghisa comments:

Hi denzel,

yes my aims are this ones:
* an admin option page to assign or reset the number of post allowed per user.
* a function to remove the number of post allowed when the user posted and to prevent the user from posting when the allowed posts are used up.
* a notice (e.g. email) for the user to contact admin, when the number of post allowed is used up.

and also

* a function that hide posts of users after a fixed number of days. the user can contact the admin in order to extend the visibility period of the posts.

Are you able to do theese functions?


Denzel Chia comments:

Hi,

I am not able to do this.
<blockquote>
* a function that hide posts of users after a fixed number of days. the user can contact the admin in order to extend the visibility period of the posts.
</blockquote>

This will need WP Cron to search for example, post that are more than 10 days old and set it back to draft status instead of publish status. The problem is WP Cron can only be trigger by visitor to your site and not a real cron. If there is no visitor, it will not be activated. And there can only be a fixed number of days for all post. Cannot have a different number of days for each user.

Thanks.

2011-02-21

Nilesh shiragave answers:

Hi

this tutorial will help you to limit the posts

http://cleverness.org/2010/08/13/limit-number-of-posts-per-user-in-wordpress/

If you set number of posts user can add is to 10.

Will it be fine if users limit completed with he added 10 posts after that users role get changed to 'subscriber' so he cant add or edit anything. then he have to contact administrator to increase the post limit and change his role again to 'editor' ?

you can achieve this by adding following code inside the functions.php file


if ( !current_user_can('manage_options') ) {
$default = 1; // default number of posts
$count_posts = 0;
global $wpdb;
$poststable = $wpdb->prefix.'posts';
$postlimit = get_user_meta($current_user->id, 'postlimit', true);
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_author = '$current_user->id' AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";
$count_posts = $wpdb->get_var($query);
if ($count_posts >= $postlimit) {
if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' )
Header("Location: index.php");//redirects to dashboard
if ( is_admin() ){
$stylesheet = get_stylesheet_directory_uri() . '/css/limitposts.css';
wp_register_style('limitpost_admin_css', $stylesheet, false, '1', 'screen');
wp_enqueue_style('limitpost_admin_css');
}
$current_user->set_role( 'subscriber');
}
}

// add post limit option to profile
add_filter('user_contactmethods','hide_profile_fields',10,1);

function hide_profile_fields( $contactmethods ) {
if( current_user_can( 'manage_options' ) )
$contactmethods['postlimit'] = 'Post Limit';
return $contactmethods;
}


and one <input> field is added to each users profile. administrator can set post limit using this field. just login with administrator account after adding above code edit any user account you will see one input box field is added with "Post Limit" as label.

2011-02-21

Ehthisham tk answers:

[[LINK href="http://wordpress.org/support/topic/limit-the-number-of-posts-a-user-can-make"]]http://wordpress.org/support/topic/limit-the-number-of-posts-a-user-can-make[[/LINK]]

2011-02-21

Vidyut Kale answers:

http://wordpress.org/support/topic/limit-the-number-of-posts-a-user-can-make

Oops. Looks like its already been said. Consider this a recommendation for the solution. :D

2011-02-21

Rashid Aliyev answers:

Use Custom Taxometres or Custom fields. Or creat Custiom filed on user profile and stpre counter there. Add +1 ühen user write something, remove -1 when user delete it's post. Or add hook on Add New Post form and check the total count of posts of user (it's WP function) and equal it to your maxium. If it's reached, do not allow user to post something.

If You need coding, we can talk about it separately.

2011-02-23

Andrea Scaglione answers:

Hi,

try this http://dsader.snowotherway.org/wordpress-plugins/limit-post-revisions-network-option/
Also you can find other plug-in that can work for you,

Andrea