How to import comments from WordPress to DISQUS

Disqus is a very nice tool to handle comments better and probably I will add it here soon, but I’ve…

Settembre 30, 2013

how to import comments into disqus from wordpress

Disqus is a very nice tool to handle comments better and probably I will add it here soon, but I’ve notice a big issue with the import of the old comments already inserted on posts. I’ve had trouble with a blog with 5 thousands comments on old posts.

The problem is in the automatic tool that imports, via ajax, the comments by examining the posts one by one, from the first post of the blog. You can find that tool in the Disqus plugin settings page after the “Advanced” paragraph, named “Import and export”:

Press “Export comments” (export from wordpress and import in disqus) to bring the comments into your Disqus. It’s an ajax tool, so you must not close the page or click on anything. It has to go on till the end:

In my case the import happens to fail always after some minutes, propbably it depends on session time or connection problems… When it stops you can restart the export everytime you want (it will not create duplicates). The export will restart the process from the first post.

Starting everytime from the first post was made to handle re-export process in case of failure, I understand it, but if you have many posts and many comments this process will never end. So, if you have many posts, during the export take note of the id of the last post examined (in the above jpg: #24828), then open the plugin script placed in /wp-content/plugins/disqus-comment-system/disqus.php and go at lines near 430. As you can see there is the query that extract the next post to examin:

SELECT *
FROM $wpdb->posts
WHERE post_type != 'revision'
AND post_status = 'publish'
AND comment_count > 0
AND ID > %d
ORDER BY ID ASC
LIMIT 1

The %d parameter is the id of the last post examined (#24828 in the above jpg) passed from javascript to the plugin. When the process fails and you restart it, it always get the first post… so, you can trick it changing the query and adding just “AND ID > 24828“:

SELECT *
FROM $wpdb->posts
WHERE post_type != 'revision'
AND post_status = 'publish'
AND comment_count > 0
AND ID > %d AND ID > 24828
ORDER BY ID ASC
LIMIT 1

So it will start where it has stopped. It’s a kind of “resume” process.

This was the only way I’ve found to export 5.000 comments from wordpress to disqus.

I’ve also noticed that the old count of number of comments at the beginning of the post was wrong, and I’ve found that it is due to conflicts with my template.

Luckly there is a checkbox to check to handle this problem and fix the number of comments shown on wordpress using Disqus:

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

Settembre 22, 2015

Social buttons: the fastest way for WordPress, without plugins

NOTE: the code in this post is written for WordPress but you can easily translate it in any language. You’re here…

Settembre 15, 2015

Optimize WordPress, a long list of tips

In the above image you can see your WordPress before reading this post, and after the optimizations you will make…

Limit the number of categories for posts in WordPress

CHOOSE ONLY ONE CATEGORY WORDPRESS If you need to limit the number of categories used by the authors of your…

Settembre 14, 2015

Remove archive pages in WordPress, how to

I think that in most blogs (that is not all) archive pages are redundant content and there’s no need to…

Settembre 8, 2015

WordPress anyone can register, but no email confirmation

Many times it has happened to me that my WordPress installation properly send emails using wp_mail directly, specifing also the…

Agosto 25, 2015