I would like to limit the number of posts which can belong to a given category, for example:

The "News" category should have no more than ten posts. When the eleventh post is created the oldest post should be dropped from the category without the need to edit the post manually to remove it from the given category.

Does it sound possible?

1 Answer 1

  1. Hook into publish_post.
  2. Check if the post is in the category news.
  3. Get all posts with that category:

    $query = new WP_Query( 
            'category_name'  => 'news', 
            'posts_per_page' => -1 
  4. Update the category of the oldest post if necessary: wp_set_post_terms().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.