Automate syndication of articles from external websites to your WordPress site using the WordPress REST API. Perfect for content aggregation, cross-posting, and syndicating posts (with proper permissions).
- Fetches and Parses HTML from external posts
- Extracts Title, Content, and Featured Image
- Uploads Media to WordPress via REST API
- Creates Draft Posts with original metadata
- Preserves Original Slug for URL consistency
- Handles Tags/Categories Dynamically
- Node.js v18+
- WordPress (with REST API enabled)
- App Password for WordPress User (for authentication)
- Axios, Cheerio, Form-Data (npm packages)
git clone https://github.com/yourusername/wp-post-copier.git
cd wp-post-copier
npm install
Create a file named wp-login.config
in the root directory.
WP_SITE_URL = 'https://yoursite.com'
WP_API_BASE = 'https://yoursite.com/wp-json/wp/v2'
WP_USER = 'your-username'
WP_APP_PASSWORD = 'your-app-password'
AUTHOR_ID = 7
CATEGORY_ID = 12
Fetch and copy a single post by passing the URL:
node wp-post-copier.js https://example.com/post-url
Create a list of URLs in posts.list
(one per line):
https://example.com/post1
https://example.com/post2
Run:
node wp-post-copier.js -l posts.list
node wp-post-copier.js -v https://example.com/post-url
The script will fetch and upload the featured image from the source post. If no image is found, the post will be created without one.
- Slug Preservation – The slug of the original post is maintained to match URLs.
- Draft Mode – Posts are created as drafts by default. You can manually publish them.
- Tag/Category Handling – If tags don't exist, the script creates them.
-
403 Forbidden (During Upload)
- Ensure the app password has upload media permissions.
- Check user roles (author/editor).
-
Invalid Parameters (author, categories, tags)
- Verify
AUTHOR_ID
andCATEGORY_ID
exist using:curl -u user:app-password https://yoursite.com/wp-json/wp/v2/users curl -u user:app-password https://yoursite.com/wp-json/wp/v2/categories
- Verify
-
Image Upload Fails
- Add
https://
to image URLs if missing. - Ensure images are not too large (WordPress max upload size).
- Add
MIT License
Pull requests are welcome! For major changes, please open an issue to discuss.