Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/post-template.php on line 284

Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/post-template.php on line 284

I met with this problem after installing The7 theme, while searching a bit I found that some people are facing this problem due to Jetpack plugin when reviewing the code I realize that this might be because of plugin or theme conflict with PHP version.

Solution:

Many people solved this problem by downgrading PHP version, but this could not be a good solution, I solved this problem by replacing this code at line 284-285 at wp-includes/post-template.php

if ( $page > count( $pages ) ) // if the requested page doesn't exist
     $page = count( $pages ); // give them the highest numbered page that DOES exist

with this code

if ( is_array( $pages ) ) {
    if ( $page > count( $pages ) ) // if the requested page doesn't exist
      $page = count( $pages ); // give them the highest numbered page that DOES exist
  } else { 	
    $page = 0;
}

 

4 COMMENTS

  1. Thanks for sharing !
    Nice snippet, the best fix I found after half an hour reading some odd workarounds here and there.
    I was not sure what was the problem related to, but now this warning message makes sense.
    Therefore, the warning is saying : “Parameter must be an array or an object”
    So for a better testing of your $pages variable, the first line should be :
    if ( is_array( $pages ) || is_object( $pages ) ) {

LEAVE A REPLY

Please enter your comment!
Please enter your name here

twenty + 9 =