With my theme, I provide "virtual" templates. There are no specific {template}.php
files in my theme, so I filtered the PAGE templates like so:
function my_virtual_templates( $templates ) {
$my_virtual_templates = array(
'virtual_template_id_1' => 'Template 1',
'virtual_template_id_2' => 'Template 2',
'virtual_template_id_3' => 'Template 3'
);
// Merge with any templates already available
$templates = array_merge( $templates, $my_virtual_templates );
return $templates;
}
add_filter( 'theme_page_templates', 'my_virtual_templates' );
I was looking for a "simple" way to add the actual post meta box on a Custom Post Type (CPT) when I came across this post. Since my new CPT will use this same array of "virtual" templates, I just needed to get a post meta box in place.
Using the theme_{$post_type}_templates It automatically creates this post meta box area for me. So where my CPT is called my_cpt
I added the filter like so:
add_filter( 'theme_my_cpt_templates', 'my_virtual_templates');
Now, the meta box and selector shows up, and I can even change on the bulk edit screen since this is all built in. Very handy!