[wp-trac] [WordPress Trac] #56590: TypeError error in get_the_content when $elements['page'] and $elements['pages'] are null

WordPress Trac noreply at wordpress.org
Fri Sep 16 21:24:27 UTC 2022


#56590: TypeError error in get_the_content when $elements['page'] and
$elements['pages'] are null
-------------------------------------+-----------------------------
 Reporter:  cantbelieveitsnotbutter  |      Owner:  (none)
     Type:  defect (bug)             |     Status:  new
 Priority:  normal                   |  Milestone:  Awaiting Review
Component:  Bootstrap/Load           |    Version:  6.0.2
 Severity:  normal                   |   Keywords:
  Focuses:                           |
-------------------------------------+-----------------------------
 `if ( $elements['page'] > count( $elements['pages'] ) )` in file `wp-
 includes/post-template.php` (currently on line 319) throws the following
 error when those array items are null:

 `Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of
 type Countable|array, null given in /wp-includes/post-template.php:319`

 A case where they would be null is a search request with no results where
 a plugin like Timber is used to assign $post a non-WordPress-core value.
 Adding the condition `if ( ! is_null( $elements['page'] ) && ! is_null(
 $elements['pages'] ) )` solves the problem.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56590>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list