WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted
  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().
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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