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?


2 Answers 2


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

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

  • 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
    Commented Jun 8, 2011 at 1:58
  • 1
    Filters & Actions are just different names. Take a look at /wp-includes/plugin.php on line 324.
    – kaiser
    Commented Jun 8, 2011 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' );

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.