#46322 closed defect (bug) (duplicate)
PHP 7.2 Warning
Reported by: | good3n | Owned by: | desrosj |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | php73 |
Focuses: | Cc: |
Description
I get the PHP warning
Warning: count(): Parameter must be an array or an object that implements Countable in /path/to/wordpress/wp-includes/post-template.php on line 293
every time I programmatically create a post with wp_insert_post()
If I go back into the post via the admin UI and update it, the warning goes away.
I'm assuming because PHP 7.2 treats this as NULL.
If I edit the /wp-includes/post-template.php
file it removes the warning.
Before (Warning):
<?php if ( $page > count( $pages ) ) { // if the requested page doesn't exist $page = count( $pages ); // give them the highest numbered page that DOES exist }
After (No Warning):
<?php if(!empty($pages)) { if ( $page > count( $pages ) ) { // if the requested page doesn't exist $page = count( $pages ); // give them the highest numbered page that DOES exist } }
Change History (6)
#4
@
6 years ago
I understand it's a duplicate but that ticket is closed.
Here is how I was able replicate the error Warning: count(): Parameter must be an array or an object that implements Countable in ... post-template.php on line 293
on the default TwentyNinenteen theme:
- Activated Easy Digital Downloads
- Created an actual post template - gist [here](https://gist.github.com/wowthemesnet/7d7893b5af6d50049a3442709bb2e476).
- Assigned the template "My account" to a random page. Published.
The template was created following Pippin's [EDD guide](https://docs.easydigitaldownloads.com/article/234-creating-a-customer-account-page)
PHP 7.2 , 7.3
@good3n Can you provide the code you are using to programmatically create a post?
Does this happen with a default theme and no plugins active on the site?