Does CSV Importer import comments?
-
sbbdc: No, currently it cannot.
I just extended the exporter to handle comments as well, to some extend. If there is interest I would be happy to share this, in the hope it will be part of a future release of cvs_importer.
knarrff: I would be interested, sure. You can send me a patch by email, which you can find in the source.
I have sent you the patch. It is not that big actually, but I am also not 100% happy with it. However, it worked for me, so I don’t have a direct reason to improve upon it anymore.
The reason why I am not really happy has to do with the way comments have to be specified – but that is inherent to the problem: Comments belong to Posts. The only easy way to connect a comment to a post in _one_ csv file I could find is to write the comment data on the same line as the post data. Now this has some problems:
- Data for one comment consists of multiple fields, but multiple comments are possible as well. This means that there has to be some comment id in the headers. This id doesn’t go into wordpress. It is only there to have the connection information in the csv file.
- The number of comments per post can be quite different from post to post. However, there has to be one header for each possible comment. This means you have to know (or guess) a number equal or greater than the maximum number of comments for any given post, and generate all of those headers. This was not a big problem for me, as I did do that import once and that number was ‘only’ 17.
- Even when a post doesn’t have that maximum number of comments, or not even a single comment, the post line has to contain a lot of empty fields, otherwise the whole post doesn’t import. That seems to be a limitation of the csv-reader. However, that’s also not a big issue because it is easy to add a lot of commas to the end of each line in the csv file. There seems to be no problem adding more of them than needed.
For illustration, here is the header I used (shortened to a maximum of three comments, but you get the idea…):
[Large code excerpt removed by moderator. Per forum rules, please use the pastebin for all large code excerpts. It works better anyway.]
knarrff: Thank you for the patch. I’ve applied it to version 0.3.1. I modified it a bit, so the following no longer holds true:
Even when a post doesn’t have that maximum number of comments, or not even a single comment, the post line has to contain a lot of empty fields, otherwise the whole post doesn’t import.
Thank you. It’s nice to know own code being used by others.
The topic ‘Does CSV Importer import comments?’ is closed to new replies.
(@sbbdc)
16 years, 3 months ago
Haven’t used this plugin yet, but would like to know if it can import comments along with posts?
http://wordpress.org/extend/plugins/csv-importer/