# Post Tags Export/Import

![License: GPLv2 or later](https://img.shields.io/badge/license-GPLv2%20or%20later-blue.svg)
![Requires: WP 5.0+](https://img.shields.io/badge/requires-WP%205.0%2B-blue.svg)
![Tested up to: 6.8](https://img.shields.io/badge/tested%20up%20to-6.8-green.svg)
![Requires PHP: 7.2+](https://img.shields.io/badge/PHP-7.2%2B-blue.svg)

A simple and lightweight WordPress plugin to export all posts (title, slug, and tags) to a JSON file and import tags from a JSON file to update posts, matching them by slug.

## Description

Do you need to back up your post tags, migrate them to another site, or perform a bulk update in a spreadsheet? **Post Tags Export/Import** is the perfect tool for the job.

This plugin provides a simple interface under **Tools -> Post Tags Export/Import** in your WordPress admin area to handle two key tasks:

1.  **Export Posts to JSON:** With a single click, you can download a clean JSON file containing the `title`, `slug`, and an array of `tags` for every post on your site.
2.  **Import Tags from JSON:** Upload a JSON file (in the same format as the one you exported) to bulk update tags. The plugin uses the post `slug` to identify which post to update and **replaces** its existing tags with the ones from the file.

This is incredibly useful for:
* Backing up and restoring tag structures.
* Editing tags offline in bulk using a text editor or script.
* Migrating tag information between staging and production environments.
* Quickly applying a new set of tags to hundreds of posts.

## Features

- **One-Click Export:** Generate a JSON file of all your posts and their tags instantly.
- **Easy Import:** Upload a JSON file to update tags.
- **Slug-Based Matching:** Reliably identifies posts using their unique slug.
- **Replace Tags:** The import functionality replaces all existing tags, giving you a clean slate.
- **Simple UI:** A clean and straightforward interface integrated into the WordPress "Tools" menu.
- **Secure:** Uses nonces to protect against CSRF attacks.

## Installation

1.  Download the latest release from the [GitHub repository](https://github.com/baiatulutata/ptei).
2.  In your WordPress admin, navigate to **Plugins -> Add New**.
3.  Click **Upload Plugin** and select the `.zip` file you downloaded.
4.  Activate the plugin.
5.  Navigate to **Tools -> Post Tags Export/Import** to use the plugin.

## How to Use

### Exporting Posts

1.  Go to **Tools -> Post Tags Export/Import**.
2.  In the "Export Posts to JSON" section, click the **Export All Posts** button.
3.  Your browser will download a file named `posts_export_YYYY-MM-DD.json`.

### Importing Tags

1.  Make sure your JSON file is correctly formatted (see below).
2.  Go to **Tools -> Post Tags Export/Import**.
3.  In the "Import Tags from JSON" section, click **Choose File** and select your JSON file.
4.  Click the **Import Tags** button.
5.  A notice will appear at the top of the page confirming how many posts were updated and how many were skipped.

## JSON File Format

The import function requires a specific JSON format. It must be an array of objects, where each object represents a post. The `slug` and `tags` keys are required for the import to work.

```json
[
    {
        "title": "My First Blog Post",
        "slug": "my-first-blog-post",
        "tags": [
            "news",
            "updates",
            "featured"
        ]
    },
    {
        "title": "A Guide to WordPress",
        "slug": "a-guide-to-wordpress",
        "tags": [
            "wordpress",
            "guide",
            "tutorial"
        ]
    },
    {
        "title": "Post Without Tags",
        "slug": "post-without-tags",
        "tags": []
    }
]