• I’m trying to import my MT blog and it’s tricky because I misuse some fields in MT (intentionally) and that’s messing up my import. I need to edit import-mt.php so that the MT body becomes the WP excerpt. I need the MT extended body to become the WP body. I’ve tried messing with the labels in my import.txt file and editing import-mt.php accordingly, but nothing seems to work.
    In my import.txt, I’m changing the “BODY” label to “SOURCE” (this is my made up field) for all entries (using find & replace). I’m changing “EXTENDED BODY” to “BODY”. I’m inserting a blank section for EXTENDED BODY below the BODY section for each entry. In effect, I’m adding an extra section, for my “source” field, above the BODY section. Meanwhile, in import-mt.php, I’m simply changing…
    // We want the excerpt
    preg_match(“|—–\nEXCERPT:(.*)|s”, $post, $excerpt);
    $excerpt = addslashes(trim($excerpt[1]));
    $post = preg_replace(“|(—–\nEXCERPT:.*)|s”, ”, $post);
    …to…
    // We want the excerpt
    preg_match(“|—–\nSOURCE:(.*)|s”, $post, $excerpt);
    $excerpt = addslashes(trim($excerpt[1]));
    $post = preg_replace(“|(—–\nSOURCE:.*)|s”, ”, $post);
    The result I’m getting when I import is that WP successfully interprets my SOURCE section as the excerpt but displays the whole remains of the entry, including the “BODY” marker and the “EXTENDED BODY” and all the dashes, as part of the excerpt. I can confirm this by going to edit an entry — the whole string from import.txt, including all the stuff for BODY, is in the excerpt field. In other words, during the import WP doesn’t stop reading import.txt for the excerpt at the dashes above the BODY label, as I would expect. Because I don’t know the exact meaning of the code above, I’m not sure where I’m going wrong.
    BTW, the reason I don’t simply edit import.txt to move the string for the BODY section down to the EXCERPT section, and the string for EXTENDED BODY up to BODY is because I can’t think of a way to do that with find & replace and I have about 1000 entries to migrate. That would require somehow leapfrogging the strings over one another in the text file.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The order in which the elements are “taken out” from the txt file (by import-mt.php) matters.

    Scott Reilly

    (@coffee2code)

    WordPress & Plugin Developer

    Assuming you don’t mind trying something I haven’t tested myself for your particular scenario (I had done something similar though), after starting with a fresh, unaltered import-mt.php file, follow these steps:
    1.) Look for this:
    // We're going to put extended body into main body with a more tag
    preg_match("|-----
    \nEXTENDED BODY:(.*)|s", $post, $extended);
    $extended = trim($extended[1]);
    if ('' != $extended) $extended = "
    \n<!--more-->\n$extended";
    $post = preg_replace("|(-----
    \nEXTENDED BODY:.*)|s", '', $post);
    Change the third and fourth lines to this:
    $post_content = addslashes(trim($extended[1]));
    //if ('' != $extended) $extended = "
    \n<!--more-->\n$extended";
    2.) Look for this:
    // Now for the main body
    preg_match("|-----
    \nBODY:(.*)|s", $post, $body);
    $body = trim($body[1]);
    $post_content = addslashes($body . $extended);
    $post = preg_replace("|(-----
    \nBODY:.*)|s", '', $post);
    Change that fourth line to this:
    $excerpt = addslashes($body);
    That should be it. This assumes that you don’t have any meaningful data in your MT excerpt field because it’ll overwrite the values obtained from the MT excerpt field with the MT body field (since that is where you wanted your WP excerpt to come from).
    -Scott

    Thread Starter emsdc

    (@emsdc)

    beautiful. This worked perfectly.
    The only problem I’m having now is that I’m getting a space above and below the output for the excerpt field. I took a quick look at the CSS. It doesn’t appear to be a CSS issue.
    I also went to edit the entry, to make sure there are no spaces above and below the excerpt in the entry form. There aren’t any spaces.
    Ideas?

    Thread Starter emsdc

    (@emsdc)

    I figured this out… I just needed to comment out this line…
    add_filter(‘the_excerpt’, ‘wpautop’);
    …in template-functions-post.php

    I’m trying to import an old MT photoblog I haven’t yet converted to WP.

    I’m using 1.5, and importing works correctly with the import-mt.php file.

    I followed the post above that gives code that worked for “emsdc”, I need to use it differently though and can’t figure out how.

    I have info in “extended body” in MT that I want to be in ‘excerpt’ in WP.

    SoMT EXPORT of mine has this info like this:

    EXTENDED BODY: has info in it
    EXCERPT: has no info at all in that line

    I want to flip flop them in importing into WP. In other words:

    I want to use EXTENDED BODY as my EXCERPT and not add EXTENDED BODY to BODY.

    I used the above code change for making the BODY from MT become EXCERPT in WP, I used that line and applied it instead to the EXTENDED BODY line.

    So when I import — the EXTENDED BODY does import into EXCERPT correctly … but EXTENDED BODY is also being imported into BODY.

    I’ve tried this and that and it doesn’t matter what the changes are I have tried, nothing has worked to not import EXTENDED ENTRY into BODY.

    So if I could ask someone to give me a clue about what to change so that EXTENDED BODY only imports as EXCERPT, and nothing else is moved at all, I’d be grateful.

    To reiterate: I need to BODY import codes to only imort “BODY” and NOT put Extended in BODY.

    Hey I figured it out! Here’s what I did.

    // We're going to put extended body into main body with a more tag
    preg_match("|-----nEXTENDED BODY:(.*)|s", $post, $extended);
    $extended = trim($extended[1]);
    //if ('' != $extended) $extended = "n<!--more-->n$extended";
    $excerpt = addslashes($extended);
    $post = preg_replace("|(-----nEXTENDED BODY:.*)|s", '', $post);

    To have the EXTENDED BODY post as EXCERPT

    // Now for the main body
    preg_match("|-----nBODY:(.*)|s", $post, $body);
    $body = trim($body[1]);
    $post_content = addslashes($body);
    $post = preg_replace("|(-----nBODY:.*)|s", '', $post);

    To have the BODY be the only thing posting as BODY.

    I found coffee2code’s post on his site which and that helped me to reinstate PART of the previous code that I needed to see if it would work … and it did. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘editing import-mt.php for misused fields’ is closed to new replies.