Support » Fixing WordPress » the_content() returns: Warning: count() error.

  • When using <?php the_content() ?> on a page template, I am recieving this error:

    Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\cmos\wordpress\wp-includes\post-template.php on line 293.

    The page has text in the back end so there should be something there to output.

    When I use <?php the_title() ?> it outputs the title fine.

    I am using WordPress 5.1.1, PHP 7.3.0.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The code on that line is
    if ( $page > count( $pages ) )
    and it’s PHP 7.3 that has that new message about Countable. So since $pages is a global variable, I would guess that your code maybe didn’t construct the Loop correctly or called functions like the_content outside the Loop or before the global variables are set.
    Supposedly, all the places where count is used have been made good for 7.3. I guess one could have been missed, though, if your code is right.

    Putting the_content() or get_the_content() inside a loop fixes. This error has been reported as a bug:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_content() returns: Warning: count() error.’ is closed to new replies.