XML(WXR) file generator for fully support official WordPress Import Plugin.
MIT License
XML(WXR) file generator for fully support official WordPress Import Plugin. Inspired By node-wxr.
npm install wxr-generator
var Importer = require('wxr-generator');
var importer = new Importer();
importer.addCategory({
slug : "perfect-category",
name: "Perfect Category"
});
console.log(importer.stringify());
Returns a new instance of Importer.
var Importer = require('wxr-generator');
var importer = new Importer({
name: 'another wordpress blog',
url: 'http://test.wordpress.com',
description: 'this is another wordpress blog test',
language: 'en-US'
});
// importer.addPost(...)
Adds new post for Importer object.
open
, it can be open
or closed
.open
, it can be open
or closed
.slug
and name
prototype.slug
and name
prototype.importer.addPost({
id: 1,
title: 'hello world',
url: 'http://localhost/hello-world.html',
slug: 'hello-world',
date: '2017-07-03 10:00:00',
author: 'admin',
content: 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!',
summary: 'Welcome',
comment_status: 'open',
ping_status: 'closed',
password: '',
categories: [{slug: 'life', name: 'Life'}, {slug: 'wp', name: 'wordpress'}],
tags: [{slug: 'blog', name: 'Blog'}],
image: 1000
})
Adds new page for Importer object. All parameters are same as addPost(options)
.
Adds new category for Importer object.
importer.addCategory({
id: 5,
parent_id: 3,
name: "Everything about JS",
slug: "js-rocks",
description: "tech about js"
})
Adds new tag for Importer object.
importer.addTag({
id: 5,
name: "JS",
slug: "js-rocks",
description: "tech about js"
})
Add new user for Importer object.
Adds new attachment(image) for Importer object.
importer.addAttachment({
id: 5,
url: "https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg",
date: "2015-10-05 00:27:25",
file: "/wp-content/upload/2015/10/05/minka.jpg",
title: "Fig. 1. Cats and puppies",
author: "admin",
description: "Fig. 1. Cats and puppies",
post_id: 3
})
// Example of adding featured image with post
let i = 100 // i should exist as the index of a loop
const image = 'http://example.com/image.jpg'
const imageId = (image) ? randomNum() : '' // use a different number range from i to avoid overlaps
importer.addPost({
id: i,
title: 'title'
slug: 'slug',
date: '2020-01-01 00:00:00',
author: 'admin',
content: 'post content',
summary: 'excerpt',
comment_status: 'closed',
ping_status: 'closed',
image: imageId
})
if(image){
importer.addAttatchment({
id: imageId,
url: image,
date: '2020-01-01 00:00:00',
title: 'title',
author: 'admin',
post_id: i
})
}
TODO
Generates result XML (WXR) string for importing to Wordpress.
var importer = new Importer();
// importer.addPost(...)
var xmlString = importer.stringify();
require("fs").writeFile("export.xml", xmlString, function(err) {
if (err) {
console.log(err);
}
console.log("File was saved! Now it's time to import.")
});
Contributions welcome!