• Resolved TwoThirdsWater

    (@twothirdswater)


    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

    (@twothirdswater)

    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.