Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1: Fatal error, when 'post_date' is '0000-00-00 00:00:00' #171

Closed
zablose opened this issue Nov 18, 2022 · 1 comment
Closed

PHP 8.1: Fatal error, when 'post_date' is '0000-00-00 00:00:00' #171

zablose opened this issue Nov 18, 2022 · 1 comment

Comments

@zablose
Copy link

zablose commented Nov 18, 2022

Hi there,

If a published post of any type has 'post_date' equals to '0000-00-00 00:00:00', on PHP 8.1, when generating sitemap, fatal error will be thrown.

wp msm-sitemap generate-sitemap

Fatal error: Uncaught TypeError: checkdate(): Argument #2 ($day) must be of type int, string given in /var/www/html/wp-includes/functions.php:7071
Stack trace:
#0 /var/www/html/wp-includes/functions.php(7071): checkdate('-1', '', '22-1')
#1 /var/www/html/wp-includes/post.php(4918): wp_checkdate('-1', '', '22-1', '22-11-18')
#2 /var/www/html/wp-includes/post.php(4189): wp_resolve_post_date('22-11-18', '')
#3 /var/www/html/wp-content/plugins/msm-sitemap/msm-sitemap.php(435): wp_insert_post(Array)
#4 /var/www/html/wp-content/plugins/msm-sitemap/includes/wp-cli.php(154): Metro_Sitemap::generate_sitemap_for_date('22-11-18')
...

The problem in this SQL query.

Due to lack of check for zero date, function 'get_post_year_range' returns range [0,2022].
After that function 'check_year_has_posts' returns [22,2022] and this is how we are getting date '22-11-18'.

Suggested fix:

$oldest_post_date_year = $wpdb->get_var( "SELECT DISTINCT YEAR(post_date) as year FROM $wpdb->posts WHERE post_status = 'publish' AND post_date > 0 ORDER BY year ASC LIMIT 1" );

I hope, you will find time, to fix this.

Thank you.

@mchanDev
Copy link
Contributor

Thanks for this, this has been accepted in #174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants