Last active
May 19, 2016 20:33
-
-
Save ronalfy/19d71ef97f664a1131b46577d247c7ab to your computer and use it in GitHub Desktop.
Custom Post Type Templates maybe_get_cpt_template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function maybe_get_cpt_template( $original_template ) { | |
$object = get_queried_object(); | |
// Check if post type template | |
if ( is_object( $object ) && is_a( $object, 'WP_Post' ) && in_array( $object->post_type, $this->post_types ) ) { | |
$maybe_template = get_post_meta( $object->ID, '_wp_page_template', true ); | |
if ( $maybe_template ) { | |
$template = get_query_template( $object->post_type, $maybe_template ); | |
if ( file_exists( $template ) ) { | |
return $template; | |
} | |
} | |
} | |
return $original_template; | |
} | |
public function register_meta_boxes() { | |
add_meta_box( 'post_type_templates', 'Choose a Template Then Update', array( $this, 'post_type_choose_templates' ), $this->post_types, 'side', 'low' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment