虽然我知道有许多类似的问题得到了回答,但这些问题帮助我找到了一个实用的解决方案,可以为我的自定义帖子类型更新页面模板,而且它工作正常。
然而,我的困难在于找到更新body_classes
与页面模板匹配的。目前,在实际更新页面模板时,不会更新body类。
add_filter( \'template_include\', \'my_template_include\', 99, 1 );
function my_template_include( $template ) {
global $post;
$meta = get_post_meta( $post->ID, \'designblocks-product-template\', true );
if ( ! $meta ) {
return $template;
}
$get_template = get_post_meta( $meta, \'_wp_page_template\', true );
if ( $get_template ) {
$template = locate_template( array( $get_template ) );
}
return $template;
}
有什么想法吗?