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 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?

Thanks

share|improve this question
add comment

2 Answers

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?

e.g.

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

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
1  
Filters & Actions are just different names. Take a look at /wp-includes/plugin.php on line 324. –  kaiser Jun 8 '11 at 2:22
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.