最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Adding the_content() return warning count()

programmeradmin2浏览0评论

I'm using the_content() function for elementor plugin implement, but warning comes up once I use this function:

Warning: count(): Parameter must be an array or an object that implements Countable

How can I fix this count() warning?

I'm using the_content() function for elementor plugin implement, but warning comes up once I use this function:

Warning: count(): Parameter must be an array or an object that implements Countable

How can I fix this count() warning?

Share Improve this question asked Jul 13, 2020 at 9:06 Yotam DahanYotam Dahan 1096 bronze badges 4
  • I noticed the same problem, I guess it's an Elementor/WP problem you can't fix. – ralphjsmit Commented Jul 13, 2020 at 9:17
  • @ralphsmit so how does other themes have Elementor working without any other issue? they disable php warnings? – Yotam Dahan Commented Jul 13, 2020 at 11:29
  • 1 True, they disable the WP_Debug in the wp-config.php. If you check the location of the error message (wp-includes/post-template.php) you can see that it is an error in a WP file. You are not responsible for the wp-includes folder, so my guess is that the Elementor developers should fix this. Btw, normal users don't have PHP warnings enabled in the first place (and as far as I know the Elementor plugin works normal). Plus, it's a warning and not an error. – ralphjsmit Commented Jul 13, 2020 at 11:32
  • 1 @ralphsmit You should write this in answer, while researching I didn't found any answer that explain it like you did. might be useful for others. – Yotam Dahan Commented Jul 13, 2020 at 11:36
Add a comment  | 

1 Answer 1

Reset to default 1

I noticed this error myself too when using the Elementor plugin. It is only displayed when WP_Debug is set to true.

The location of the warning is wp-includes/post-template.php. This is not a theme location, so the short version is that you're not responsible for it.

The error only appears when using Elementor. I think that the Elementor developers should fix this error, because it is their plugin that 'conflicts' with a wp-includes file. I expect that this will be fixed in a future version of Elementor.

My conclusion is that you can ignore this error message. It is only visible when WP_Debug is true and normal users seldom enable this. Plus, it is only a warning and not an error. As far as I know, the Elementor plugin is not hindered by it. (However, this could turn into an error in a future version of PHP when it is not fixed.) But for now you shouldn't worry.

UPDATE PER 15/7/2020:

This error is caused by only using the_content() function outside of a loop. This function should be put inside a loop.

So replace

the_content();

with

    while ( have_posts() ) : the_post();
        the_content();
    endwhile; 

Replacing this made the error disappear, while my content and everything didn't change. My guess now is that the count() function has to do sth with the wp count in the loop.

发布评论

评论列表(0)

  1. 暂无评论