표시를 처리하기 위해 독립 템플릿 (single-post_type_1.php 및 single-post_type_2.php)으로 리디렉션하려는 두 가지 사용자 지정 게시물 유형 (예 : post_type_1 및 post_type_2)이 있습니다. 각각의 플러그인 폴더에 자체적으로 포함되도록 디스플레이 템플릿을 테마 폴더에 넣고 싶지 않습니다.
서로 영향을주지 않고 template_redirect 후크를 각각 등록하도록하려면 어떻게해야합니까? 아니면 다른 기술을 사용해야합니까?
현재 플러그인 1 에서이 작업을 수행하고 있습니다.
add_action( 'template_redirect', 'template_redirect_1' );
function template_redirect_1() {
global $wp_query;
global $wp;
if ( $wp_query->query_vars['post_type'] === 'post_type_1' ) {
if ( have_posts() )
{
include( PATH_TO_PLUGIN_1 . '/views/single-post_type_1.php' );
die();
}
else
{
$wp_query->is_404 = true;
}
}
}
그리고 플러그인 2의 경우 :
add_action( 'template_redirect', 'template_redirect_2' );
function template_redirect_2() {
global $wp_query;
global $wp;
if ( $wp_query->query_vars['post_type'] === 'post_type_2' ) {
if ( have_posts() )
{
include( PATH_TO_PLUGIN_2 . '/views/single-post_type_2.php' );
die();
}
else
{
$wp_query->is_404 = true;
}
}
}
플러그인 2의 template_redirect 후크를 등록하면 플러그인 1이 더 이상 작동하지 않습니다.
뭔가 빠졌습니까?
가장 좋은 방법은 무엇입니까?