title: Using WP_Query() to check if a post exists by slug
body: <p>I am writing a 404.php for wordpress. I have the plugin 'rolescoper' installed, and some pages require the user be logged in to view.  Rolescoper doesn't offer any way to distinguish between a page not found (404) and a permission denied (403). </p>
  
  <p>I've been able to build this functionality into my pages using the following code:</p>
  
  <pre><code>$the_query = new WP_Query ( 'pagename=' . $_SERVER['REQUEST_URI'] );
  $is_valid_page = ! empty ( $the_query -&gt; queried_object -&gt; post_title );
  </code></pre>
  
  <p>But, surprisingly, the same method does does not work for posts:</p>
  
  <pre><code>$args = array (
     'post_type' =&gt; 'post',
     'name' =&gt; str_replace ( "/", "", $_SERVER['REQUEST_URI'] )  
  );
  
  $the_post_query = new WP_Query ( $args );
  $is_valid_post = ! empty ( $the_post_query -&gt; queried_object -&gt; post_title );
  </code></pre>
  
  <p>When I do a var_dump on <code>$the_post_query</code> i get something that shows 0 results found. I am sure that the page I'm checking for exists.</p>
  
  <p>Any idea how to use <code>wp_query()</code> to query for a post by slug?</p>
  
  <p>Thanks!</p>