• Unlike other people I was impressed by this plugin’s ability to import all my data from my old blog while preserving all the ids etc, even with WordPress 4.0.

    One thing though, for some reasons many posts with a [gallery] shortcode in them failed to show up anything. It turned out that the media relative to the post was actually there, just not correctly parented. In other words it was orphaned and wasn’t available as a proper attachment to their original post as they should have.

    I suspect that the problem for those posts was that in my previous blog, for gallery posts, I was adding the media before saving the post itself, so their id number was lower than the post itself. This, together with the fact that the script had to run multiple times before successfully downloading all the media, ended up messing up the parenting.

    Unfortunately re-running the script doesn’t help as the code that handles parenting won’t run when the post has already been imported. This is easily fixed by moving that code before the check, like this:

    — wordpress-importer.php.bck 2014-10-29 00:56:50.740583913 +0000
    +++ wordpress-importer.php 2014-10-29 00:57:32.654508642 +0000
    @@ -554,24 +554,25 @@

    $post_type_object = get_post_type_object( $post[‘post_type’] );

    + // do this anyway for subsequent processing
    + $post_parent = (int) $post[‘post_parent’];
    + if ( $post_parent ) {
    + // if we already know the parent, map it to the new local ID
    + if ( isset( $this->processed_posts[$post_parent] ) ) {
    + $post_parent = $this->processed_posts[$post_parent];
    + // otherwise record the parent for later
    + } else {
    + $this->post_orphans[intval($post[‘post_id’])] = $post_parent;
    + $post_parent = 0;
    + }
    + }
    +
    $post_exists = post_exists( $post[‘post_title’], ”, $post[‘post_date’] );
    if ( $post_exists && get_post_type( $post_exists ) == $post[‘post_type’] ) {
    printf( __(‘%s “%s” already exists.’, ‘wordpress-importer’), $post_type_object->labels->singular_name, esc_html($post[‘post_title’]) );
    echo ‘
    ‘;
    $comment_post_ID = $post_id = $post_exists;
    } else {
    – $post_parent = (int) $post[‘post_parent’];
    – if ( $post_parent ) {
    – // if we already know the parent, map it to the new local ID
    – if ( isset( $this->processed_posts[$post_parent] ) ) {
    – $post_parent = $this->processed_posts[$post_parent];
    – // otherwise record the parent for later
    – } else {
    – $this->post_orphans[intval($post[‘post_id’])] = $post_parent;
    – $post_parent = 0;
    – }
    – }

    // map the post author
    $author = sanitize_user( $post[‘post_author’], true );
    if ( isset( $this->author_mapping[$author] ) )

    This worked for me.

    Hopefully some developer will have a look at this – I couldn’t find any other simple way to submit patches, and this could turn out useful to someone else as well in the meanwhile.

    Related to this, a button to re-run the import code without having to re-upload the .xml file would come handy as having to run the code multiple times seems like a common occurrence.

    I hope this helped, cheers.

    https://www.ads-software.com/plugins/wordpress-importer/

  • The topic ‘It should attempt to fix parents even when the posts are all there already’ is closed to new replies.