1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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);

ドハマリした。。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?