Title: Custom 404 for &#039;draft&#039; posts
Last modified: August 21, 2016

---

# Custom 404 for 'draft' posts

 *  Resolved [TwoThirdsWater](https://wordpress.org/support/users/twothirdswater/)
 * (@twothirdswater)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/custom-404-for-draft-posts/)
 * My clients site shows content for a period of time, after which the status is
   automatically set to draft, which means any users visiting the old URL get a 
   404 message.
 * I’d like to be able to customise that 404 message to suggest relevant content
   based on the page that isn’t available any more. Is there a way to find out the
   target page / posts ID on a 404 page?
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [TwoThirdsWater](https://wordpress.org/support/users/twothirdswater/)
 * (@twothirdswater)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/custom-404-for-draft-posts/#post-4025584)
 * I managed to figure this out. It seems the post ID isn’t available via code directly,
   but if we grab the URI of the page we are on, its possible to get the post object
   from the function **get_page_by_path**
 * Code that works for me is:
 *     ```
       $page_path = $_SERVER["REQUEST_URI"];
       $postObject = get_page_by_path( basename( untrailingslashit( $page_path ) ) , OBJECT, 'post');
       ```
   
 * Though I think some servers might not return you the request URI.

Viewing 1 replies (of 1 total)

The topic ‘Custom 404 for 'draft' posts’ is closed to new replies.

## Tags

 * [status](https://wordpress.org/support/topic-tag/status/)

 * 1 reply
 * 1 participant
 * Last reply from: [TwoThirdsWater](https://wordpress.org/support/users/twothirdswater/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/custom-404-for-draft-posts/#post-4025584)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
