web-dev-qa-db-ja.com

データベースに挿入される前にタグをフィルタリングするために使用できるフィルタはありますか?

データベースに挿入される前にタグをフィルタリングしたいです。私は pre_insert_term フィルタを知っています。しかし、私がする必要があるのは一度にすべてのタグを見ることです。 1回の投稿でデータベースに入力されるタグの数を制限する必要があります。これを行うためのフィルタはありますか?それとも他の方法?

ありがとう

1
Can't Tell

タグの数を変更するためにwp_set_post_tags()Codex ref )を使用して、それをsave_postまたはpublish_post、あるいは必要に応じてどこにでもフックすることについてはどうでしょうか。

例えば.

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' );
1
Chip Bennett

良いことに - いつものように - アクションリファレンス です。

$post上のpre_post_updateデータからの用語をcountにすることができます。

1
kaiser