假设提供的代码片段可以工作,那么像这样扩展条件语句将对您有所帮助,
function filter_post_type_link($link, $post)
{
if ($post->post_type = \'custom_post_type_1\') {
if ($cats = get_the_terms($post->ID, \'custom_cat_1\'))
$link = str_replace(\'%custom_cat_1%\', array_pop($cats)->slug, $link);
return $link;
} elseif ($post->post_type = \'custom_post_type_2\') {
if ($cats = get_the_terms($post->ID, \'custom_cat_2\'))
$link = str_replace(\'%custom_cat_2%\', array_pop($cats)->slug, $link);
return $link;
} else {
return $link;
}
}
add_filter(\'post_type_link\', \'filter_post_type_link\', 10, 2);