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 want to filter the tags before they are inserted into the database. I'm aware of the pre_insert_term filter. But what I need to do is to see all the tags at once. I need to limit the number of tags entered to the database per post. Is there a filter to do this? Or any other method?


share|improve this question

A good thing - as always - is the Action Reference.

You could count the terms from the $post data on pre_post_update.

share|improve this answer
Thanks for your answer. I did take a look at that. But from what I understood, it is an action and not a filter. A $post_id is passed to it according to the source. So I don't think that will work. Even if I get the post using the $post_id, it will return what is in the database right? What I want is to filter this before it gets to the database. – Can't Tell Jun 8 '11 at 1:58
Filters & Actions are just different names. Take a look at /wp-includes/plugin.php on line 324. – kaiser Jun 8 '11 at 2:22

What about using wp_set_post_tags() (Codex ref) to modify the number of tags, and then hooking that into save_post or publish_post or wherever, as appropriate?


function mytheme_limit_post_tags( $post_id ) {
    // code to count/limit the number of tags
    // then pass the modified list of tags to wp_set_post_tags
    wp_set_post_tags( $post_id, $tags, false );
add_action( 'publish_post', 'mytheme_limit_post_tags' );
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.