我最终使用了index_template
当CPT单页被错误地重定向到索引时,筛选以加载正确的模板,并且$_SERVER[\'REQUEST_URI\']
包含CPT的段塞。像这样:
add_filter(\'index_template\', \'wpse300393_resolve_cpts_with_dots_in_name\');
function wpse300393_resolve_cpts_with_dots_in_name($templates = \'\'){
if( strpos($_SERVER[\'REQUEST_URI\'], \'artwork\') !== false ){
$templates = locate_template( \'single-artwork.php\' );
}
elseif( strpos($_SERVER[\'REQUEST_URI\'], \'artist\') !== false ){
$templates = locate_template( \'single-artist.php\' );
}
return $templates;
}