title: Checking whether post_parent = 0 in WordPress
body: <p>I am creating a site using WordPress using a theme which has this PHP at the top of each page and I am confused as to what it does.</p>
  
  <pre><code>&lt;?php 
  global $post;
  global $wp_query;
  if ( $post-&gt;post_parent != 0 ) {
      $thePostID = $post-&gt;post_parent;
  } else {
      $thePostID = $wp_query-&gt;post-&gt;ID;
  };
  ?&gt;
  </code></pre>
  
  <p>I was just wondering if anyone could explain exactly what this does? I think it checks to see if the <code>post_parent</code> <code>id</code> is <code>0</code> which isn’t allowed in WordPress and sets the post <code>id</code> to the <code>post_parent</code> but I’m not 100% sure.</p>