Ticket #14847: featured_image_import.2.diff

File featured_image_import.2.diff, 1.3 KB (added by Nano8Blazex, 2 years ago)

revised

  • wordpress-importer.php

     
    5454 
    5555        var $fetch_attachments = false; 
    5656        var $url_remap = array(); 
     57        var $thumb_posts = array(); 
    5758 
    5859        function WP_Import() { /* nothing */ } 
    5960 
     
    600601 
    601602                                                update_post_meta( $post_id, $key, $value ); 
    602603                                                do_action( 'import_post_meta', $post_id, $key, $value ); 
     604                                                 
     605                                                // if the post has a featured image, take note of this in case of remap 
     606                                                if ( $key == '_thumbnail_id' ) { 
     607                                                        // store the post id and value 
     608                                                        $this->thumb_posts[$post_id] = $value; 
     609                                                } 
    603610                                        } 
    604611                                } 
    605612                        } 
     
    852859                        // remap enclosure urls 
    853860                        $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); 
    854861                } 
     862                 
     863                // Cycle through posts that have a featured image 
     864                foreach ( $this->thumb_posts as $post_id => $value ) { 
     865                        // Check if its metadata needs updating 
     866                        if ( isset( $this->processed_posts[$value] ) ) { 
     867                                $new_id = $this->processed_posts[$value]; 
     868                                 
     869                                if ( $new_id != $value ) { 
     870                                        // update metadata 
     871                                        $value = $new_id; 
     872                                        update_post_meta( $post_id, '_thumbnail_id', $new_id ); 
     873                                } 
     874                        } 
     875                } 
    855876        } 
    856877 
    857878        /**