> 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://whoisandywhite.gitbook.io/porterwp/documentation/porter-past-status-updater.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
