PHPackages                             humanmade/orphan-command - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. humanmade/orphan-command

ActiveWp-cli-package[CLI &amp; Console](/categories/cli)

humanmade/orphan-command
========================

WP-CLI command to list and delete orphan WordPress entities and metadata.

1.1.1(1y ago)4519.1k—4.5%6[1 issues](https://github.com/humanmade/orphan-command/issues)GPL-3.0-or-laterPHPPHP &gt;=7.2

Since Jan 9Pushed 1y ago18 watchersCompare

[ Source](https://github.com/humanmade/orphan-command)[ Packagist](https://packagist.org/packages/humanmade/orphan-command)[ Docs](https://github.com/humanmade/orphan-command)[ RSS](/packages/humanmade-orphan-command/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

Orphan Command
==============

[](#orphan-command)

> WP-CLI command to list and delete orphan WordPress entities and metadata.

---

Introduction
------------

[](#introduction)

WordPress offers dedicated APIs that are to be used for CRUD operations on the various core data structures. For example, when you delete a comment via `wp_delete_comment( $comment_id, true )`, WordPress takes care that all metadata for that comment gets automatically deleted as well. Great!

However, people do not always do what is right—on purpose, or by accident. The reason for that could be that someone deleted entities and/or metadata directly in the DB (instead of using the respective WordPress API to handle that data). This might make sense when you want to reduce a large production or staging database export, and therefore delete (random) posts etc. Or maybe someone only did a partial database import, or partial migration. Over time, you might end up with a database that is full of orphaned entries. Comment metadata for comments that no longer exist, comments for non-existing posts, or revisions of posts that don't exist anymore.

Orphan Command provides a new WP-CLI command, `wp orphan`, that lets you easily spot orphans, and even delete them, if you want.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
    - [Composer](#composer)
    - [Manual](#manual)
- [Requirements](#requirements)
    - [PHP](#php)
    - [WordPress](#wordpress)
    - [WP-CLI](#wp-cli)
- [Commands](#commands)
    - [`wp orphan blog meta`](#wp-orphan-blog-meta)
    - [`wp orphan comment`](#wp-orphan-comment)
    - [`wp orphan comment meta`](#wp-orphan-comment-meta)
    - [`wp orphan post`](#wp-orphan-post)
    - [`wp orphan post meta`](#wp-orphan-post-meta)
    - [`wp orphan revision`](#wp-orphan-revision)
    - [`wp orphan term meta`](#wp-orphan-term-meta)
    - [`wp orphan user meta`](#wp-orphan-user-meta)
    - [Run all commands](#run-all-commands)
- [Extending Orphan Command](#extending-orphan-command)
- [Frequently Asked Questions](#frequently-asked-questions)

Installation
------------

[](#installation)

### Composer

[](#composer)

Install with [Composer](https://getcomposer.org):

```
composer require humanmade/orphan-command
```

By default, Orphan Command will be installed as WP-CLI package. However, it **can** also be installed as WordPress plugin, for example, by using [a custom install path](https://github.com/composer/installers#custom-install-paths).

### Manual

[](#manual)

In case you're not managing your entire site via Composer, you can also clone this repository into your site's plugins directory.

```
cd /path/to/plugins

git clone git@github.com:humanmade/orphan-command.git
```

Then, install and set up PHP auto-loading:

```
cd orphan-command

composer install --prefer-dist --no-dev
```

Finally, go to your site's Plugins page, and activate Orphan Command.

Requirements
------------

[](#requirements)

### PHP

[](#php)

Orphan Command **requires PHP 7.2 or higher**.

### WordPress

[](#wordpress)

Orphan Command **requires WordPress 3.3 or higher**.

### WP-CLI

[](#wp-cli)

Orphan Command **requires WP-CLI 2.5 or higher**.

Commands
--------

[](#commands)

In general, all commands support the following three **actions**:

- **`delete`**: Delete all orphans of the respective entity type.
- **`list`**: List all orphans of the respective entity type.
- **`query`**: Print the MySQL query to list all orphans of the respective entity type.

By default, the output of `list` is a comma-separated list of IDs. This can be changed by using the `--format` option, which supports the following values:

- **`count`**: The number of orphans.
- **`csv`**: Orphan IDs to be exported into a CSV file.
    - Sample usage: `wp orphan post list --format=csv > orphan-posts.csv`
- **`ids`**: Orphan IDs as a single comma-separated string.
- **`json`**: Orphan IDs to be exported into a JSON file.
    - Sample usage: `wp orphan post list --format=json > orphan-posts.json`
- **`table`**: Orphan IDs printed as a table (with a single column only).
- **`yaml`**: Orphan IDs to be exported into a YAML file.
    - Sample usage: `wp orphan post list --format=yaml > orphan-posts.yaml`

Some commands support additional options that are explained in the following sections.

### `wp orphan blog meta`

[](#wp-orphan-blog-meta)

The `wp orphan blog meta` command lets you list and delete all **blog metadata** referencing **blogs** that don't exist anymore.

**List all orphan blog metadata:**

```
wp orphan blog meta list
```

**Delete all orphan blog metadata:**

```
wp orphan blog meta delete
```

### `wp orphan comment`

[](#wp-orphan-comment)

The `wp orphan comment` command lets you list and delete all **comments** referencing **posts** that don't exist anymore.

In addition to `--format`, the `wp orphan comment` command also supports the following options:

- **`--type`**: Comma-separated list of comment type slugs.
    - Sample usage: `--type=comment` or `--type=comment,reaction`

**List all orphan comments of any comment type:**

```
wp orphan comment list
```

**List all orphan reactions:**

```
wp orphan comment list --type=reaction
```

**Delete all orphan comments of any comment type:**

```
wp orphan comment delete
```

**Delete all orphan default comments only:**

```
wp orphan comment delete --type=comment
```

**Note:** Since comments can be nested (i.e., a comment can have a parent comment), an orphan comment *could* also be a comment referencing another comment that does not exist anymore. This is **not** what this command does, though. The main reason is that a comment referencing a non-existing post will usually not be exposed to site visitors.

A future version of Orphan Command might allow to also list/delete comments referencing non-existing parent comments.

### `wp orphan comment meta`

[](#wp-orphan-comment-meta)

The `wp orphan comment meta` command lets you list and delete all **comment metadata** referencing **comments** that don't exist anymore.

**List all orphan comment metadata:**

```
wp orphan comment meta list
```

**Delete all orphan comment metadata:**

```
wp orphan comment meta delete
```

### `wp orphan post`

[](#wp-orphan-post)

The `wp orphan post` command lets you list and delete all **posts** referencing parent **posts** that don't exist anymore.

In addition to `--format`, the `wp orphan post` command also supports the following options:

- **`--type`**: Comma-separated list of post type slugs.
    - Sample usage: `--type=post` or `--type=post,page`

**List all orphan posts of any post type:**

```
wp orphan post list
```

**List all orphan pages:**

```
wp orphan post list --type=page
```

**Delete all orphan posts of any post type:**

```
wp orphan post delete
```

**Delete all orphan default posts only:**

```
wp orphan post delete --type=post
```

### `wp orphan post meta`

[](#wp-orphan-post-meta)

The `wp orphan post meta` command lets you list and delete all **post metadata** referencing **posts** that don't exist anymore.

**List all orphan post metadata:**

```
wp orphan post meta list
```

**Delete all orphan post metadata:**

```
wp orphan post meta delete
```

### `wp orphan revision`

[](#wp-orphan-revision)

The `wp orphan revision` command lets you list and delete all **revisions** referencing original **posts** that don't exist anymore.

Revisions are one of the Custom Post Types included in WordPress. Since they are somewhat special in that a revision with a non-existing original (parent) post is of no use whatsoever, and since there is a dedicated API for revisions (e.g., `wp_delete_post_revision`), Orphan Command provides a custom command for managing revisions.

**List all orphan revisions:**

```
wp orphan revision list
```

**Delete all orphan revisions:**

```
wp orphan revision delete
```

### `wp orphan term meta`

[](#wp-orphan-term-meta)

The `wp orphan term meta` command lets you list and delete all **term metadata** referencing **terms** that don't exist anymore.

**List all orphan term metadata:**

```
wp orphan term meta list
```

**Delete all orphan term metadata:**

```
wp orphan term meta delete
```

### `wp orphan user meta`

[](#wp-orphan-user-meta)

The `wp orphan user meta` command lets you list and delete all **user metadata** referencing **users** that don't exist anymore.

**List all orphan user metadata:**

```
wp orphan user meta list
```

**Delete all orphan user metadata:**

```
wp orphan user meta delete
```

### Run all commands

[](#run-all-commands)

```
wp core is-installed --network && wp orphan blog meta list
wp orphan comment list
wp orphan post list
wp orphan post meta list
wp orphan revision list
wp orphan term meta list
wp orphan user meta list
```

Extending Orphan Command
------------------------

[](#extending-orphan-command)

If you want to customize or extend the functionality of Orphan Command, you can either extend any of the actual command classes, or you could write your own based on either the `Orphan_Command` or `Orphan_Meta_Command` class included in Orphan Command.

All relevant class methods are marked `protected` or `public`, so you can redefine or decorate any behavior. For example, the `Orphan_Post_Command` class enhances the `get_query` method to inject the post type passed to the command, if any.

Frequently Asked Questions
--------------------------

[](#frequently-asked-questions)

> **What about terms?**

For terms, there is no clear definition of orphans. An orphan term could be defined in one of several ways:

- An entry in the `wp_terms` table that is not referenced at all in the `wp_term_taxonomy` table. (This is most likely **not** what you want, most of the time.)
- An entry in the `wp_term_taxonomy` table referencing a non-existing term (i.e., `wp_term_taxonomy.term_id` does not exist in `wp_terms.term_id`).
- An entry in the `wp_term_taxonomy` table referencing a non-existing parent term (i.e., `wp_term_taxonomy.parent` does not exist in `wp_terms.term_id`).
- An entry in the `wp_term_relationships` table referencing a non-existing object. (This would either require the taxonomy, or the object type to then use all registered taxonomies.)

To some extent, this is similar to comments. However, there it is more of an interpretation issue, which is why Orphan Command, by default, defines orphan comments as comments referencing non-existing posts.

A future version of Orphan Command might allow to also list/delete orphan terms.

> **What about site/network metadata or options?**

The terminology in WordPress around blog metadata and options, network options, and site metadata and options is quite confusing!

Some facts:

- Orphan Command supports blog meta.
- Options live in dedicated tables on a per-site basis, which means there cannot be any orphan options.
- While it makes sense to manage site (i.e., network) metadata, Orphan Command currently does not allow for this. The main reason really is to prevent people from accidentally deleting the wrong data.
- A future version of Orphan Command might allow to also list/delete site metadata.

> **What about use case XYZ?**

Yes, there are most certainly several possible use cases around orphan data and metadata missing. However, this is on purpose.

While it may be a good idea to list all users of a specific role that are not added to any site, or to delete all orphan posts with a specific status, this would be out of scope.

Orphan Command provides easy access to tasks that a lot of people might want to perform a lot of times; not more.

That said, you should be able to use existing WP-CLI commands such as `wp  list|delete` or `wp db query` to accomplish any of the above examples quite easily.

License
-------

[](#license)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~356 days

Total

5

Last Release

530d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6049306?v=4)[Thorsten Frommen](/maintainers/tfrommen)[@tfrommen](https://github.com/tfrommen)

---

Top Contributors

[![tfrommen](https://avatars.githubusercontent.com/u/6049306?v=4)](https://github.com/tfrommen "tfrommen (13 commits)")[![roborourke](https://avatars.githubusercontent.com/u/23417?v=4)](https://github.com/roborourke "roborourke (5 commits)")[![tomjn](https://avatars.githubusercontent.com/u/58855?v=4)](https://github.com/tomjn "tomjn (5 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (3 commits)")[![johnbillion](https://avatars.githubusercontent.com/u/208434?v=4)](https://github.com/johnbillion "johnbillion (2 commits)")[![nlemoine](https://avatars.githubusercontent.com/u/2526939?v=4)](https://github.com/nlemoine "nlemoine (1 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/humanmade-orphan-command/health.svg)

```
[![Health](https://phpackages.com/badges/humanmade-orphan-command/health.svg)](https://phpackages.com/packages/humanmade-orphan-command)
```

###  Alternatives

[fuel/oil

FuelPHP 1.x Oil Package

1051.2M5](/packages/fuel-oil)[ceeram/clear_cache

Clear CakePHP caches from shell, app or debug\_kit panel

85123.8k3](/packages/ceeram-clear-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
