Live Blog

Bulk Create Discourse Threads from WordPress Posts

This site started using WordPress comments, then I moved the comments to Disqus, and then on to Discourse. Unfortunately, there is no bulk way to create topics for each WordPress post that existed before implementing the WordPress Discourse plugin.

I found this thread on the Discourse forum.

What I ended up doing was using the WP cli tool as follows

$wp post update 396 398 402 {several more here} –tags_input=discourse
Before this I retrieved a list of row ID’s from the wp_posts table that had post_status = ‘publish’ and post_type = post

I gave that list to the wp post command and it took about 500ms per row using a 4core server. If I specified more than 20 or so rows, Discourse would… ???.. but after that no more links would be made. So I fed it 20 at a time with a 30 second delay and worked on other projects.

So, that answer is a for-real hack, but for me (not yet having @angus answer), it was the most direct route.

https://meta.discourse.org/t/is-it-possible-to-bulk-create-threads-for-many-wordpress-posts-sql-maybe/201210/7

This method works great if you have 5-10 posts, but if you have 50+, it will be tedious. I created this bash one-liner to loop through all the posts and updated them.

for post_id in $(wp post list --post_type=post --post_status=publish --format=ids); do
  wp post update "$post_id" --post_status=publish
done
0 Shares: