Created
April 24, 2016 11:48
-
-
Save sairam/c6560f0b08206763c7839f367b5e8fc2 to your computer and use it in GitHub Desktop.
Restore Old Wordpress Posts to Octopress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem install mysql2 | |
# import mysqldump to database | |
# fix database name | |
require 'mysql2' | |
client = Mysql2::Client.new(:host => "localhost", :username => "root", database: "wp") | |
results = client.query(%Q{select post_modified, POST_NAME, POST_TITLE, post_content from wordpress_posts}) | |
results.entries.each do |e| | |
file_to_touch = e["post_modified"].to_s.split(" ")[0] + "-"+ e["POST_NAME"]+".html" | |
data = %Q{ | |
--- | |
layout: post | |
title: #{e["POST_TITLE"]} | |
date: #{e["post_modified"]} | |
comments: false | |
categories: | |
--- | |
#{e["post_content"]} | |
} | |
t = open(file_to_touch,"w+") | |
t.write(data) | |
t.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment