For add a select page template option for custom post type just add below code into your theme's functions.php file or your custom plugin file.
For add a select page template option for custom post type just add below code into your theme's functions.php file or your custom plugin file. add meta box for custom post type
<!--?php add_action('add_meta_boxes','rj_add_page_template_metabox');function rj_add_page_template_metabox() { $screens = array('things_to_do','restaurant','attraction','destination','hotel'); foreach($screens as $screen) { add_meta_box('posttemplaterj', __('Page Template','avada'), 'rj_page_template_option',$screen, 'side', 'core'); }}?-->this function is for meta box callback action for display page templates dropdown box
<!--?php function rj_page_template_option($post) { if (in_array( $post->post_type ,array('things_to_do','restaurant','attraction','destination','hotel'))&& 0 != count( rj_get_page_templates() ) ) { $template = get_post_meta($post->ID,'_post_template',true); ?--><label class="screen-reader-text" for="rj_post_template"><!--?php _e('Page Template','avada') ?--></label><select name="rj_post_template" id="rj_post_template"><option value="default"><!--?php _e('Default Template','avada'); ?--></option> <!--?php rj_get_page_template_dropdown($template); ?--></select><!--?php } ?--><!--?php }?-->Below function for get all page templates from theme or its child theme.
<!--?php function rj_get_page_templates() { $themes = get_themes(); $theme = get_current_theme(); $templates = $themes[$theme]['Template Files']; $post_templates = array(); if ( is_array( $templates ) ) { $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) ); foreach ( $templates as $template ) { $basename = str_replace($base, '', $template); if ($basename != 'functions.php') { if ( false !== strpos($basename, '/') ) continue; $template_data = implode( '', file( $template )); $name = ''; if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) $name = _cleanup_header_comment($name[1]); if ( !empty( $name ) ) { $post_templates[trim( $name )] = $basename; } } } } return $post_templates;}?-->Below code create a dropdown box of page template's exists in theme or its child theme
<!--?php function rj_get_page_template_dropdown( $default = '' ) { $templates = rj_get_page_templates(); ksort( $templates ); foreach (array_keys( $templates ) as $template ) : if ( $default == $templates[$template] ) $selected = " selected='selected'"; else $selected = ''; echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>"; endforeach;}?-->Save page template meta box value while user save post.
<!--?php add_action('save_post','rj_save_page_template',10,2);function rj_save_page_template($post_id,$post) { if (in_array( $post->post_type ,array('things_to_do','restaurant','attraction','destination','hotel')) && !empty($_POST['rj_post_template'])) update_post_meta($post->ID,'_post_template',$_POST['rj_post_template']);}?-->Assign page template in front-end for custom post type if user selected page template for that post.
<!--?php add_filter('single_template','rj_get_page_or_post_template_for_template_loader');function rj_get_page_or_post_template_for_template_loader($template) { global $wp_query; $post = $wp_query->get_queried_object(); if ($post) { $post_template = get_post_meta($post->ID,'_post_template',true); if (!empty($post_template) && $post_template!='default') $template = locate_template($post_template); } return $template;}?-->
