Limit Post Creation Count to posts only
-
Hello
So I have a store that allows users to buy things from my woocommerce store and at the same time post their own posts, but I’ve been wanting to limit the amount of posts my users can make, and furtunitly i found this sniippet here. The problem now is that when users pass the post limit, all their new posts turn into drafts and so does their new woocommerce order status. Is there a way to limit this to only work on WordPress posts?P.S.
I’m novice at web developmentHere is the code:
add_filter( 'wp_insert_post_data', function( $data, $postarr ) { $posts_per_month = 10; // Could be set as an updatable option $user_id = get_current_user_id(); // Number of posts in current month by this user $author_posts = new WP_Query( array( 'post_type' => 'any', 'post_status' => 'publish', 'author' => $user_id, 'fields' => 'ids', 'monthnum' => date( 'm' ), // Whatever the current month is ) ); $author_post_count = $author_posts = $author_posts->post_count + 1; // Add current post if( $author_post_count > $posts_per_month ) { $data['post_status'] = 'draft'; } return $data; }, 10, 2 );
Thank you in advance.
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Limit Post Creation Count to posts only’ is closed to new replies.