您可以使用term\\u link filter来完成。大致如下:
function my_term_link($termlink, $term, $taxonomy) {
global $post;
if ($taxonomy == \'my-custom-taxonomy\') {
return get_permalink( $post->ID ) . \'#\' . $term->term_id;
}
}
while ( $programtype->have_posts() ) : $programtype->the_post();
$terms = get_the_terms( $post->ID, \'my-custom-taxonomy\' );
add_filter(\'term_link\', \'my_term_link\', 10, 3);
foreach ($terms as $term) {
$link = get_term_link( $term, \'my-custom-taxonomy\' );
// Use link here
}
remove_filter(\'term_link\', \'my_term_link\', 10, 3);
endwhile;