Only the page
post type can have a template assigned (of the default post types), it’s the custom template you set in the Page Attributes meta box. If you have a page.php
template file, your index.php
will only be used to display post
post types, so those posts will never have a _wp_page_template
meta key. As to why you don’t get any pages with your index.php
loop, only the post
post type gets queried on home and archive pages. If you want to get all posts and pages on your home page, use pre_get_posts
to modify the home page query:
function wpa83038_posts_and_pages_on_home( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'page' ) );
}
}
add_action( 'pre_get_posts', 'wpa83038_posts_and_pages_on_home' );
I’m not sure how useful that would be though. Seems you’d want to do another custom query for pages and keep posts separate.