Update:
Page Template Usage Info in WordPress 4.4+
In WordPress 4.4 the array_intersect_assoc()
was removed from the WP_Theme::get_page_templates()
method.
See ticket #13265 and changeset #34995.
We can therefore add the page templates usage info, directly into the template dropdown, with the theme_page_templates
filter, without using javascript or some clever object cache tricks explained here by @MikeSchinkel or here by @gmazzap.
Here's a demo (PHP 5.4+):
add_filter( 'theme_page_templates', function( $page_templates, $obj, $post )
{
// Restrict to the post.php loading
if( ! did_action( 'load-post.php' ) )
return $page_templates;
foreach( (array) $page_templates as $key => $template )
{
$posts = get_posts(
[
'post_type' => 'any',
'post_status' => 'any',
'posts_per_page' => 10,
'fields' => 'ids',
'meta_query' => [
[
'key' => '_wp_page_template',
'value' => $key,
'compare' => '=',
]
]
]
);
$count = count( $posts );
// Add the count to the template name in the dropdown. Use 10+ for >= 10
$page_templates[$key] = sprintf(
'%s (%s)',
$template,
$count >= 10 ? '10+' : $count
);
}
return $page_templates;
}, 10, 3 );
Example:
Here we can see how it could look like, with the usage count info added to the template names :
Hope you can adjust this to your needs!