This is default get_template_part function inside WordPress:
function get_template_part( $slug, $name = null ) {
do_action( "get_template_part_{$slug}", $slug, $name );
$templates = array();
if ( isset($name) )
$templates[] = "{$slug}-{$name}.php";
$templates[] = "{$slug}.php";
locate_template($templates, true, false);
}
I am trying to use that action for locating custom post type loop file from plugin:
add_action( "get_template_part_templates/loop", function($slug, $name){
if ("example" == $name){
if (!locate_template("templates/loop-{$name}.php", false, false)){
/* What do you suggest to do here? */
}
}
},10,2 );
I need a solution that;
- Check if theme have files for "example" custom post type
- If dont have; use plugin's template files for showing and dont use theme's default solution
Update: this is the code that calling template part in theme:
global $post;
get_template_part( 'templates/loop', $post->post_type );