MTKeyValues functionality (5 posts)

  1. dgthomson
    Posted 12 years ago #

    Finding that WP supports Custom Fields has convinced me that I should migrate from MT. My old installation makes a lot of use of the MTKeyValues plugin-- a broadly similar concept to Custom Fields.
    ...so what would be nice if the import-mt.php script could interpret these key/value pairs and form Custom Fields for the relevant entries.
    In my MT export, I have various tags in the format:
    (Image information)
    comment=Mark McMillan has signed a two year deal at Leeds
    I suppose the interpretation code would be something like:
    if (keyvalue pairs are present) {
    $keyvalue = explode("\n",$extendedentry);
    (skip first line- can't be used for keyvalue pairs)
    foreach ($keyvalue as $line)
    ($key[],$value[]) = explode("=",$line);
    That's the extent of my php knowledge; any takers to complete the fix?

  2. philipd
    Posted 12 years ago #

    I just found WordPress the other day and I realized that I wanted the exact same thing as you. I used the MTKeyValues plugin and was disappointed that the import-mt.php script just ignored the whole KEYWORDS section. But I guess it's understandable since some people want to do other things with their keywords, like make them into slugs.
    Anyway, I modified the stock import-mt.php script to import key=value type keywords, as well as bare keywords (I convert them into keywords=keyword1 keyword2 keyword3, etc...).
    I've got a patch that you can apply — I'm not sure if it will look good if I post it here, but I'll give it a try. Just copy it into your wp-admin directory and type this: patch import-mt.php import-mt.php.patch
    --- import-mt.php 2004/07/02 16:54:58 1.1
    +++ import-mt.php 2004/07/03 03:14:58
    @@ -192,7 +192,9 @@
    preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
    $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
    - // We ignore the keywords
    + // We want the keywords
    + preg_match("|-----\nKEYWORDS:(.*)-----|s", $post, $keywords);
    + $keywords = addslashes(trim($keywords[1]));
    $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
    // We want the excerpt
    @@ -271,12 +273,27 @@
    } // end switch
    } // End foreach
    + // Split the keywords up
    + $postmeta = array();
    + $keywords = explode("\n", $keywords);
    + foreach ($keywords as $line) {
    + if ($line == '') continue;
    + preg_match("/^(.*?)=(.*)/", $line, $token);
    + $key = trim($token[1]);
    + $value = trim($token[2]);
    + if ($key == '') {
    + $key = 'keywords';
    + $value = $line;
    + }
    + $postmeta[$key] = $value;
    + }
    // Let's check to see if it's in already
    if ($wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$post_title' AND post_date = '$post_date'")) {
    echo "Post already imported.";
    } else {
    $post_author = checkauthor($post_author);//just so that if a post already exists, new users are not created by checkauthor
    - $wpdb->query("INSERT INTO $tableposts (
    + $wpdb->query("INSERT INTO $tableposts (
    post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt)
    ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_name','$post_date', '$post_date_gmt')");
    @@ -308,6 +325,15 @@
    if (!$exists) $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_id, 1) ");
    echo " Post imported successfully...";
    + foreach ($postmeta as $key => $value) {
    + $exists = $wpdb->get_row("SELECT * FROM $tablepostmeta WHERE post_id = $post_id AND meta_key = '$key' AND meta_value = '$value'");
    + if (!$exists) {
    + $wpdb->query("INSERT INTO $tablepostmeta (post_id, meta_key, meta_value) VALUES ($post_id, '$key', '$value')");
    + echo " Postmeta added.";
    + }
    + }
    // Now for comments
    $comments = explode("-----\nCOMMENT:", $comments[0]);
    foreach ($comments as $comment) {

  3. philipd
    Posted 12 years ago #

    Um… &#92n should be \n

  4. carthik
    Posted 12 years ago #

    philipd, do you have an url for that diff?
    I maintain a list of resources for folks moving from mt to wp, and if you don't mind can you please email me the diff, or the patched import-mt.php ?
    the email address is mail @ carthikk dot net
    Thank you. :)

  5. adamrice
    Posted 9 years ago #

    This patch seems to have been superceded by the current version of WP. Any chance of updating it?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.