title: Wordpress doesn't select page template for parent pages
body: <p>I'm developing a WP Theme and I'm having this issue that's driving me crazy...</p>
  <p>For every single (parent) page I create, WP chooses <code>index.php</code> as template. I'm aware of WP template hierarchy but it doesn't matter if I use <code>page.php</code>, <code>page-$slug.php</code> or <code>page-$id.php</code>, I've also tried using:</p>
  <pre><code>&lt;?php
    /*
    Template Name: My Template 
    */
  ?&gt;
  </code></pre>
  <p>and assigning the page this template in the Editor.</p>
  <p>I've also hooked, for debugging purposes, <code>template_include</code> as follows:</p>
  <pre><code>add_filter( 'template_include', 'check_template_selection', 99 );
  
  function check_template_selection( $template ) {
      global $post;
      echo &quot;Post ID: &quot; . $post-&gt;ID . &quot;&lt;br/&gt;&quot;;
      echo &quot;Template File:&quot; . $template . &quot;&lt;br/&gt;&quot;;
      echo is_page() ? &quot;YES&quot; : &quot;NO&quot;;
      return $template;
  }
  </code></pre>
  <p>And for every page URL I check (for example: <code>http://example.com/mypage</code>) I'm getting:</p>
  <blockquote>
  <p>Post ID:</p>
  <p>Template File:/nfs/c11/h05/mnt/205383/domains/<em>example.com</em>/html/wp-content/themes/<em>mytheme</em>/index.php</p>
  <p>NO</p>
  </blockquote>
  <p>I've tried deleting the pages and creating them again, but it's the same. The fact is it works fine for child pages. For example: <code>http://example.com/mypage/mychildpage</code> shows:</p>
  <blockquote>
  <p>Post ID:589</p>
  <p>Template File:/nfs/c11/h05/mnt/205383/domains/<em>example.com</em>/html/wp-content/themes/<em>mytheme</em>/page-mychildpage.php</p>
  <p>YES</p>
  </blockquote>
  <p>I'm using WP 4.4.2, ACF PRO 5.3.6.1, Custom Post Type UI 1.2.4 and Instagram Feed Pro Personal 2.0.4.1. No other plugins. Anyway, I tried unsuccessfully to desactivate them all. I've developed the theme from scratch and I've done dozens of themes before and I've never experienced this issue before...</p>
  <p>This is my <code>.htaccess</code> and my permalinks are properly configured as <code>/%postname%/</code>, no category base.</p>
  <pre><code># BEGIN WordPress
  
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  
  # END WordPress
  </code></pre>
  <p>So please, any advice or hint on what am I missing here would be very apreciated. Thank you guys!</p>
  <hr />
  <h2>Edit:</h2>
  <p>After hours of deep search (Thank you so much John Blackbourn for your <a href="https://wordpress.org/plugins/query-monitor/" rel="nofollow noreferrer">Query Monitor</a> plugin) I found that my parent pages match the wrong rewrite rule, so now I guess it's something about rewrite rules priority.</p>
  <p><strong>Wrong match for a parent page URL:</strong> <code>http://example.com/about</code></p>
  <p><a href="https://i.stack.imgur.com/d0wZC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d0wZC.png" alt="Wrong Match" /></a>
  <a href="https://i.stack.imgur.com/x6lBt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x6lBt.png" alt="Wrong Rule Selected" /></a></p>
  <p><strong>Right match for a child page URL:</strong> <code>http://example.com/about/about-child</code></p>
  <p><a href="https://i.stack.imgur.com/538pj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/538pj.png" alt="Right Match" /></a>
  <a href="https://i.stack.imgur.com/foJqL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/foJqL.png" alt="Right Rule Selected" /></a></p>