Adding the_content() return warning count()

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x