以下代码改编自Jan Fabry的回答。Mixing custom post type and taxonomy rewrite structures?
<?php
add_filter(\'post_type_link\', \'client_area_permalink\', 10, 4);
function client_area_permalink($post_link, $post, $leavename, $sample) {
if ( false !== strpos( $post_link, \'%client_category%\' ) ) {
$glossary_letter = get_the_terms( $post->ID, \'client_category\' );
$post_link = str_replace( \'%client_category%\', array_pop( $glossary_letter )->slug, $post_link );
}
return $post_link;
}
?>
当我去添加新帖子时,array_pop
引发错误。我相信这是因为这篇文章还没有相关的分类法。
如何修复此错误?我考虑过使用get_post_permalink
作为基地,因为那是post_type_link
被钩住了。