Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andreas Paulsson 9 posts 29 karma points
    Sep 20, 2010 @ 22:51
    Andreas Paulsson
    0

    Tags in imported blog posts are not set correctly.

    I recently wrote a Wordpress XML import (blog posts, comments and tags) for umbraco blog based on Morten Bock's article at http://www.mortenbock.dk/blog/2009/10/13/importing-wordpress-posts-to-umbraco.aspx (I had to adjust a few things, though to make it work with Umbraco 4.5.1 and the Wordpress XML document that I received from the client) and now everythin works correctly except the tags.

    I get the tags from the Wordpress XML and add them to each post. When I look at the imported post, the tag is set correctly and the blog:s category list list all tags and the number of posts that are tagged with each tag. The problem is that when I click on a tag to filter on it, I get zero posts.

    Upon closer investigation, it seems that the tags are not set in umbraco.config either. But if I go to the post in the Content tree, view the post and press "Save and Publish", umbraco.config is updated and filtering by tags show the post that I have save and published again.

    The code that I am using to import posts is:

                XNamespace wpns = XNamespace.Get("http://wordpress.org/export/1.0/");

                XNamespace contentns = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");

                var q = from c in xDocument.Descendants("item")

                        where (string)c.Element(wpns + "post_type") == "post"

                        select c;

     

                DocumentType dt = DocumentType.GetByAlias("BlogPost");

                User author = User.GetUser(0);

     

                foreach (XElement item in q)

                {

                    string posttitle = (string)item.Element("title");

                    string postbody = (string)item.Element(contentns + "encoded");

                    string posttags = string.Empty;

                    DateTime createdate = DateTime.Parse((string)item.Element(wpns + "post_date"));

     

                    int i = 0;

                    foreach (XElement tag in item.Elements("category"))

                    {

                        if ((string)tag.Attribute("domain") == "category" &&

                            !string.IsNullOrEmpty(tag.Value))

                        {

                            if (i > 0)

                            {

                                posttags += ",";

                            }

                            posttags += tag.Value;

                            i++;

                        }

                    }

     

                    Document doc = Document.MakeNew(posttitle, dt, author, blogPostParentNodeId);

                    doc.CreateDateTime = createdate;

                    doc.ReleaseDate = createdate;

                    doc.getProperty("PostDate").Value = createdate;

                    doc.getProperty("bodyText").Value =

                        WordpressPostParser.ParseCodeBlocks(

                            WordpressPostParser.ChangeImageUrls(WordpressPostParser.CreateParagraphTags(postbody), originalHostname, originalMediaFolderUrl, newMediaFolderUrl));

                    doc.CreateDateTime = createdate;

                    doc.Publish(author);

                    if (!string.IsNullOrEmpty(posttags))

                    {

                        Tag.AddTagsToNode(doc.Id, posttags, "default");

                    }

                    doc.Publish(author);

                    library.UpdateDocumentCache(doc.Id);

     

                    //comments here...

     

    I have tried a few different versions for adding tags (with and without publish before adding tags, calling save before, ...etc) but nothing works. I have also looked at the blogML importer but it does not seem to import tags at all.

    Can anyone see anything wrong with the code?

     

     

     

  • Andreas Paulsson 9 posts 29 karma points
    Sep 22, 2010 @ 11:13
    Andreas Paulsson
    0

    I also realized that after customer has been saving each post, the category list list twice as many posts for each post as there actually are.

    See http://www.asa-torstensson.se/blog.aspx for an example.

     

     

  • Chris 69 posts 75 karma points
    Feb 27, 2011 @ 13:46
    Chris
    0

    Hi Andreas,

    Did you find a solution for the tags problem? I am creating content nodes with the tags datatype. And same like you, the tags are saved but not added to umbraco.config. Only after i do a manual 'save & publish' the tags show up.

    Thanks,

    Chris 

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Feb 28, 2011 @ 08:40
    Richard Soeteman
    0

    Hi Chris,

    When you publish the page using the API it's the same as the manual save and publish , from the top of my head these are the steps:

    doc.Save();

    doc.Publish(new User(0));

    umbraco.library.UpdateDocumentCache(doc.Id);

    Cheers,

    Richard

  • Chris 69 posts 75 karma points
    Mar 02, 2011 @ 08:36
    Chris
    0

    Hi Richard,

    Thanks for your reply. But these are the steps that I use in my code already... So, there must be something missing to get the tags published... (They are saved and associated to the content nodes however. So, I'm thinking its a caching issue...)

    Chris

  • Chris 69 posts 75 karma points
    Mar 02, 2011 @ 08:41
    Chris
    0

    I forgot to mention that I started a new forum post before being pointed to this post. So maybe best to continue the conversation there. :) 

    http://our.umbraco.org/forum/developers/api-questions/17813-Publish-node-with-tags-datatype

     

Please Sign in or register to post replies

Write your reply to:

Draft