1
2

More than 5 years have passed since last update.

add_filterで複数引数を扱う場合は指定が必要

Posted at

wp_count_postsadd_filterして処理をフックしようとすると以下のエラーが発生。

Fatal error: Uncaught ArgumentCountError: Too few arguments to function ...

引数の数が不正とのこと。
結論として、add_filterの第4引数に、関数に渡す引数の数を指定する必要がある。
初期値は1だから1つしかとれてないのね。

add_filter('wp_count_posts', function($counts, $type, $perm) {
    // 処理内容
}, 10, 3);

ドハマリした。。

参考
- 関数リファレンス/add filter - WordPress Codex 日本語版
- ワードプレスで寄稿者に画像アップ権限を付ける+自身の所有メディアしかリストさせない|コンサルティング事業部ブログ|株式会社アクセスジャパン

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2