网站报错count(): Parameter must be an array or an object的解决方法
WordPress的网站如果采用php7,那么评论位置就会出现一个报错警告,类似Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/oswhy.com/wp-includes/class-wp-comment-query.php on line 399
这个报错是php7版本引起的,当传递一个无效参数的时候,count()函数会抛出warning的警告,更新到php8.2版本即可解决,如果不想更新php版本,那么可以修改网站对应文件,提示count()参数必须是一个数组或一个对象,所以方法就是直接将它设为数组。
$this->comment_count = count( $this->comments );
修改为
$this->comment_count = count((array) $this->comments );
