> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/documentation/porter-past-status-updater.md).

# Porter\_PastStatusUpdater

`Porter_PastStatusUpdater` is a helper base class for content that should move into a custom `past_{post_type}` status once a date field has passed. It is designed for event-style content, but it can be used anywhere you need date-driven status changes.

## Location

* `includes/helpers/class-Porter_PastStatusUpdater.php`
* Auto-loaded by `includes/porter-helper-functions.php`

## What it does

* Registers a custom `past_*` post status.
* Adds a rewrite rule so single URLs continue to resolve.
* Adds a "Past" filter tab to the admin list screen.
* Schedules an hourly cron job to move old posts into the past status.
* Adjusts status during save if the date is already in the past.
* Supports optional migration from a legacy meta flag.
* Can cascade the past status to child posts.

## Minimum implementation

```php
class EventPastStatusUpdater extends Porter_PastStatusUpdater {
    protected function get_post_type() {
        return 'event';
    }

    protected function get_date_source( WP_Post $post ) {
        return get_post_meta( $post->ID, 'end_date', true );
    }

    protected function get_meta_key() {
        return 'event_has_past';
    }

    protected function children_inherit_parent_status() {
        return false;
    }
}

new EventPastStatusUpdater();
```

## Required and optional methods

| Method                             | Required | Purpose                                                                                   |
| ---------------------------------- | -------- | ----------------------------------------------------------------------------------------- |
| `get_post_type()`                  | Yes      | Returns the target custom post type slug.                                                 |
| `get_date_source( WP_Post $post )` | Yes      | Returns the value used to decide whether the post is in the past.                         |
| `get_meta_key()`                   | No       | Returns a legacy meta flag key used by `migrate_existing()`. Defaults to an empty string. |
| `get_cron_hook()`                  | No       | Overrides the cron hook name. Defaults to `update_{post_type}_past_status`.               |
| `get_status()`                     | No       | Overrides the post status slug. Defaults to `past_{post_type}`.                           |
| `children_inherit_parent_status()` | No       | Returns whether child posts should also be moved to the past status. Defaults to `true`.  |

## Accepted date formats

The class supports three date-source styles:

* `YYYYMMDD`
* Unix timestamps
* Any string `strtotime()` can parse

## Lifecycle

1. On `init`, the class registers the custom past status and adds the single-post rewrite rule.
2. It ensures single front-end requests for the target post type include both `publish` and the custom past status.
3. It schedules an hourly cron job if one is not already registered.
4. On save, it immediately swaps the post into or out of the past status based on the date source.
5. It exposes manual update and migration triggers in `/wp-admin/`.

## Manual triggers

The helper supports two admin-side shortcuts:

* `/wp-admin/?updateEvent=1`
* `/wp-admin/?migrateEvent=1`

The suffix comes from `ucfirst( get_post_type() )`, so adjust the query string to match your post type slug.

## Migration behaviour

If `get_meta_key()` returns a value, `migrate_existing()` will:

* query posts where that meta key equals `1`
* move them into the custom past status
* preserve taxonomy terms
* delete the legacy meta flag afterwards

## Notes

* The hourly updater checks posts in `publish` and the custom past status.
* The registered past status is publicly queryable for single URLs, but excluded from search.
* If child posts should stay independent, override `children_inherit_parent_status()` to return `false`.
* If single past posts 404 after first install on an existing site, flush permalinks once.
