• Resolved crazyred

    (@crazyred)


    Hi all

    Recently, after updating wordpress 4.4.1 to 4.4.2, I figured out that all my posts post_type’s value where set to “post” in the database.

    The results is that all pages, menus, attachments, etc…. where gone from there original location and the site got broken.. but i could found all of them in the admin Post page..

    I haven’t found any topic on this matter else than this one https://www.ads-software.com/support/topic/all-pages-empty-after-update-to-442?replies=5 where it is the exact same situation.

    But instead of changing manually each post type to its original value, I just used some backup to downgrade to 4.4.1.

    I made several test local and online but until now I haven’t been able to correct the problem.

    Things I noted :
    the database update also query SET NAMES utf8mb4, which turned the standard wp tables into utf8mb4_unicode_ci..

    I wonder if someone else experiment similar issues and knows more about it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter crazyred

    (@crazyred)

    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.

    Thread Starter crazyred

    (@crazyred)

    Ok I was wrong, my version was not 4.4.1 but 4.1.1 then I found the solution, and there is a thread on this known issue.

    https://www.ads-software.com/support/topic/42-update-turned-all-pages-into-posts-big-mess?replies=35

    The problem came with 4.1.1 that has no db_version number defined which results in calling all upgrading functions.

    Resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘All post_type set to "post" after update to 4.4.2’ is closed to new replies.