---
url: /hooks/filters/wpce-before-document-from-post.md
description: >-
  Filter the post reference before Document::from_post() creates a WPCE
  document.
---

# `wpce_before_document_from_post`&#x20;

Filters the post when a [`Document`](https://bitbucket.org/ownbit/ownbit-wpce/src/dev/plugin/includes/WPCE/Document.php) is loaded via `Document::from_post`.

## Parameters

1. `?WP_Post $post`

   The post to load the document for. May be `null` to indicate that the post should be detected from the environment (e.g. the loop's current post or a `$_GET['post']` parameter).

2. `bool $preview`

   Whether the document is being loaded as a preview.

## Example

```php
add_filter('wpce_before_document_from_post', function (?WP_Post $post, bool $preview) {
	// ...

	return $post;
}, 10, 2);
```

## Related

* [`wpce_before_document_load`](./wpce-before-document-load)
* [`wpce_before_document_from_json`](./wpce-before-document-from-json)
* [`wpce_before_document_from_rest_request`](./wpce-before-document-from-rest-request)
* [`wpce_before_document_from_save_request_body`](./wpce-before-document-from-save-request-body)
* [`wpce_after_document_from_post`](../actions/wpce-after-document-from-post)
