ClassicPress database error Incorrect DATETIME value: '0' for query SELECT p.ID FROM wp_posts AS p WHERE p.post_date < '0'

After switching to ClassicPress 1.7.3 my error_log file started filling with these errors: ClassicPress database error Incorrect DATETIME value: ‘0’ for query SELECT p.ID FROM wp_posts AS p WHERE p.post_date < ‘0’ AND p.post_type = …

I was able to identify that the cause was line 1692 in wp-includes/link-template.php:

$current_post_date = $post->post_date;

I fixed it by adding this to the next line below:

if (!$current_post_date) $current_post_date=date(“Y-m-d H:i:s”);

Is there possibly a better fix for this?

a more slightly elegant solution I found was to add the following new code outside of any core files, like in a new plugin or the theme functions:

function bmn_filter_adjacent_post_where($where, $in_same_term, $excluded_terms, $taxonomy, $post) {
$regEx = ‘/(\.post_date\s*+[<!=>]++\s*+)\’0\’/i’;
if (preg_match($regEx, $where)) {
if ($post->post_date_gmt)
$where = preg_replace($regEx, “\\1’$post->post_date_gmt’”, $where);
return $where;
}
}
add_filter(‘get_next_post_where’, ‘mn_filter_adjacent_post_where’, 100, 5);
add_filter(‘get_previous_post_where’, ‘bmn_filter_adjacent_post_where’, 100, 5);

// but the real question this brings up is: why does $post->post_date_gmt contain a valid date and $post->post_date just return a 0 ?

It could be a plugin/theme that conflicts and stops the function in that file you identified from the error… so before using that specific code I would dig deeper and find the real culprit and correct its code…
here in Italy 2026 has just started as of 7 minutes ago - so my best wishes for the new year.

1 Like

CP version 1 is not under active development anymore, so why switch to it?