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.
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.
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 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...)
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?
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.
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
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
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
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
is working on a reply...