Exporting content from WordPress for Hugo #

Part 3 of Moving from WordPress to Hugo

Part 3 of Moving from WordPress to Hugo

The starting point is Cyrill Schumacher’s WordPress to Hugo exporter.

This WordPress plugin isn’t in the WordPress plugin gallery, so needs to be installed directly to your WordPress site either via FTP or by SSH and a git clone.

There are clear usage instructions in the README, it’s worth noting that the time to run is very dependent on how much content you have in your site, and how much processor capacity you have. I found when running it via the web browser that I got a couple of 504 timeout errors until it finally worked and downloaded a zip file of the exported content. If you have SSH access to your web server there is also a CLI option to avoid running through the web request pipeline.

I have previously customised my WordPress site with a couple of custom post types. Obviously Cyrill’s code doesn’t know about those, so they were missing from the first download.

The code is fairly straightforward, and it’s possible to add custom post types to the export by modifying one line:

 hugo-export.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hugo-export.php b/hugo-export.php
index 1e008e0..36bdd03 100644
--- a/hugo-export.php
+++ b/hugo-export.php
@@ -99,7 +99,7 @@ function get_posts()
         global $wpdb;
-        return $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status in ('publish', 'draft', 'private') AND post_type IN ('post', 'page' )");
+        return $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status in ('publish', 'draft', 'private') AND post_type IN ('post', 'page', 'syn_worknote', 'syn_linklog' )");

Uploading this edited version of the plugin and repeating the export process yielded a zip file with the missing content now added.

Proactive application of technology to business

My interests include technology, personal knowledge management, social change