{"id":26295509,"url":"https://github.com/ericrasch/script-export-wp-posts","last_synced_at":"2025-03-15T04:14:16.855Z","repository":{"id":281245084,"uuid":"944673789","full_name":"ericrasch/script-export-wp-posts","owner":"ericrasch","description":"This script automates the export of WordPress posts, pages, and all [public] custom post types, as well as custom permalinks, and user data using WP-CLI.","archived":false,"fork":false,"pushed_at":"2025-03-11T18:22:48.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T19:31:12.625Z","etag":null,"topics":["export","script","wordpress","wp-post-list","wpcli"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericrasch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-07T19:07:10.000Z","updated_at":"2025-03-11T18:33:36.000Z","dependencies_parsed_at":"2025-03-11T19:31:32.727Z","dependency_job_id":"1eb6e18d-480f-4276-a873-7cbad4a3b27a","html_url":"https://github.com/ericrasch/script-export-wp-posts","commit_stats":null,"previous_names":["ericrasch/export-wp-posts","ericrasch/script-export-wp-posts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-export-wp-posts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-export-wp-posts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-export-wp-posts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericrasch%2Fscript-export-wp-posts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericrasch","download_url":"https://codeload.github.com/ericrasch/script-export-wp-posts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243681077,"owners_count":20330155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["export","script","wordpress","wp-post-list","wpcli"],"created_at":"2025-03-15T04:14:16.221Z","updated_at":"2025-03-15T04:14:16.774Z","avatar_url":"https://github.com/ericrasch.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Export WordPress Posts \u0026 Users with WP-CLI**\n\n## **Overview**  \nThis script automates the export of **WordPress posts, pages, and all [public] custom post types, as well as custom permalinks (if you're using the [Custom Permalinks plugin](https://wordpress.org/plugins/custom-permalinks/)), and user data** using **WP-CLI**. It generates structured CSV files containing post details, user data, and post counts per user.\n\n## **Why did I make this?**  \nI work on a lot of WordPress sites with a lot of post/pages/post_types and having all of this info in a spreadsheet really helps me organize and find issues (like duplicate permalinks). Gathering all of the data for a site and uploading it to Google Sheets used to be a real chore. This script automates all the data gathering and allow me to upload and manage a single sheet, saving me hours of work. \n\n## **Why Use This Script?**  \n✔ **Exports all WordPress posts \u0026 their metadata**  \n✔ **Captures custom permalinks for accurate SEO mapping**  \n✔ **Exports a complete list of WordPress users**  \n✔ **Appends post counts per user across all public post types**  \n✔ **Formats data into clean, structured CSV files**  \n\n---\n\n## **How It Works**  \n1. **Retrieves all posts** from the WordPress database using WP-CLI  \n2. **Fetches custom permalinks** for posts (if they exist)  \n3. **Cleans and merges post data** into a single structured CSV file  \n4. **Extracts user data**, including email, roles, and post count  \n5. **Generates multiple output CSV files** for easy analysis or migration  \n\n---\n\n## **Installation \u0026 Setup**  \n### **1️⃣ Save the Script**  \n- Place the script in a directory, e.g., `~/scripts/export_wp_posts.sh`\n- Ensure it has **execute permissions**:\n  ```bash\n  chmod +x ~/scripts/export_wp_posts.sh\n  ```\n\n### **2️⃣ Run the Script Manually**  \n```bash\n~/scripts/export_wp_posts.sh\n```\n\n---\n\n## **Customizing for Your System**  \nTo use this script on your own system, you may need to adjust the following:\n\n1. **Ensure WP-CLI is installed**  \n   - Run `wp --info` to confirm WP-CLI is available. If not, install it from: [WP-CLI Installation Guide](https://wp-cli.org/#installing).\n\n2. **Run WP-CLI as the correct user**  \n   - If your WordPress install runs under a different user (e.g., `www-data`), you may need to prefix commands with:\n     ```bash\n     sudo -u www-data wp post list --allow-root\n     ```\n\n3. **Modify export folder location**  \n   - By default, the script saves files in `!export_wp_posts/`. Change `EXPORT_DIR` in the script if needed.\n\n---\n\n## **Output Files**  \nAll exported files are stored in the `!export_wp_posts/` directory:\n\n- `export_all_posts.csv`: Contains all WordPress posts and metadata.\n- `export_custom_permalinks.csv`: Captures custom permalinks (if they exist).\n- `export_wp_posts_\u003ctimestamp\u003e.csv`: Final merged post export.\n- `export_users.csv`: Raw list of WordPress users.\n- `export_users_with_post_counts.csv`: Users with post counts appended.\n- `export_debug_log.txt`: Debug log (if DEBUG mode is enabled).\n\n---\n\n## **Automating the Process**  \nInstead of running this script manually, you can **automate it using different methods**:\n\n### **1️⃣ Schedule Automatic Execution (Using `cron`)**  \nRun the script **every day at midnight**:\n\n```bash\ncrontab -e\n```\n\nAdd this line to **run the script daily**:\n```bash\n0 0 * * * ~/scripts/export_wp_posts.sh\n```\n✅ **Fully automated daily exports!**  \n\n---\n\n### **2️⃣ Quick Terminal Command (Using an Alias)**  \nCreate a **shortcut command** for easy execution:\n\n```bash\necho 'alias exportposts=\"~/scripts/export_wp_posts.sh\"' \u003e\u003e ~/.bashrc\nsource ~/.bashrc\n```\nNow, simply type:\n```bash\nexportposts\n```\n✅ **Quick \u0026 easy manual execution!**  \n\n---\n\n## **Customization \u0026 Expansion**  \nYou can **modify this script** to support additional functionality:  \n🛠 **Export WooCommerce product data** by adding `wp post list --post_type=product`  \n🛠 **Sync exported files to cloud storage** (e.g., AWS S3, Google Drive)  \n🛠 **Trigger automatic imports into another WordPress site**  \n\n---\n\n## **License**  \nThis project is licensed under the **MIT License**. You are free to use, modify, and distribute it as needed. See the `LICENSE.md` file for full details.  \n\n---\n\n## **Final Thoughts**  \n🔥 This script **simplifies WordPress data exports** and ensures you have structured backups of your posts and users. Whether you're migrating, analyzing content, or auditing users, this tool makes the process fast and efficient.  \n\n🎯 **Ready to automate your WordPress data exports?** Give it a try! 🚀\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fscript-export-wp-posts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericrasch%2Fscript-export-wp-posts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericrasch%2Fscript-export-wp-posts/lists"}