Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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( 
        array(
            '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
add comment

Your Answer

 
discard

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.