Display revision if post status is pending

It took me a while but I got it! This works as follows:

  1. Since you have no reference to the post other than the URI, we segment out the URI to check for a page with that page_name
  2. If there is a page, we get the latest revision child
  3. Hack the query to force our revision slug to source the page

This works swell because it gives the appearance of a working permalink. It acts as a pseudo permalink.

add_action( 'wp', 'override_404' );
function override_404($query) {

    if(is_404):

        $uri = trim($_SERVER['REQUEST_URI'], "https://wordpress.stackexchange.com/");
        $segments = explode("https://wordpress.stackexchange.com/", $uri);
        $slug_index = count($segments);

        $page_slug = $segments[$slug_index - 1];
        $page = get_page_by_path($page_slug, OBJECT, 'page');

        $revision_args = array('post_parent' => $page->ID, 'post_type' => 'revision', 'post_status' => 'inherit', 'numberposts' => 1);
        $revision = array_shift(get_children($revision_args));

        if($revision):
            $query->query_vars['pagename'] = $revision->page_name;          
            $query->query_string = "pagename={$revision->page_name}";
            $query->request = $revision->page_name;
            $query->matched_rule = "({$revision->page_name})(/[0-9]+)?/?$";
            $query->matched_query = "pagename={$revision->page_name}&page=";
            $query->did_permalink = 1;
        endif;

    endif;

    return $query;
}

The only caveat is sometimes the slug does not save until you publish the page. In order for this to work correctly, the slug must be in the database. Cheers!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)