为了避免这样的错误,您必须检查$glossary\\u letter的值是否为数组。由于get\\u the\\u terms()在失败时返回false,因此您只需检查$glossary\\u letter是否为false,并将其设置为空数组,以平息array\\u pop()的错误。
<?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\' );
// adding check and reset
if ( !$glossary_letter ) { $glossary_letter = array(); }
// continue as you were
$post_link = str_replace( \'%client_category%\', array_pop( $glossary_letter )->slug, $post_link );
}
return $post_link;
}
?>