Post limit snippet drafts orders
-
Hello,
So I’m using this snippet to limit published posts on my wordpress site. The problem is when a user’s post is published and he tries to order a product, it automatically drafts his order too.
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' => 'post', '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 );
Here is also a link to another support ticket I made Click
- The topic ‘Post limit snippet drafts orders’ is closed to new replies.