After some more digging,
I found that upgrading process run trough functions that are checking for $wp_db_current_version
which is stored in ‘wp_options’ table and it ‘option_name ‘ value is ‘db_version’.
I checked my version value which is set to ‘30135’, defined lastly by the 4.4.1 wp-includes/version.php line:14 $wp_db_version = 30135;
Then, in the wp-admin/includes/upgrade.php, there is the following function :
function upgrade_210() {
global $wpdb, $wp_current_db_version;
if ( $wp_current_db_version < 3506 ) {
// Update status and type.
$posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
if ( ! empty($posts) ) foreach ($posts as $post) {
$status = $post->post_status;
$type = 'post';
if ( 'static' == $status ) {
$status = 'publish';
$type = 'page';
} else if ( 'attachment' == $status ) {
$status = 'inherit';
$type = 'attachment';
}
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) );
}
}
if ( $wp_current_db_version < 3845 ) {
populate_roles_210();
}
if ( $wp_current_db_version < 3531 ) {
// Give future posts a post_status of future.
$now = gmdate('Y-m-d H:i:59');
$wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");
$posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");
if ( !empty($posts) )
foreach ( $posts as $post )
wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID));
}
}
and this specific part :
if ( $wp_current_db_version < 3506 ) {
// Update status and type.
$posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
if ( ! empty($posts) ) foreach ($posts as $post) {
$status = $post->post_status;
$type = 'post';
if ( 'static' == $status ) {
$status = 'publish';
$type = 'page';
} else if ( 'attachment' == $status ) {
$status = 'inherit';
$type = 'attachment';
}
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) );
}
}
…seems to be the culprit of setting post_type to ‘post’ !!
So the question is now: why is this upgrade function is called since my db_version should be greater than 3506. Plus, it means that all the upgrading functions might have been called during the upgrade process…
For the moment I suspect that the db_version value were not stored into the variable, which causes all the upgrade functions to mess up the database.