您可以使用get_the_terms( int|WP_Post $post, string $taxonomy )
. 参见Codex详细信息here.
// put IDs of your selected three categories e.g. 15, 18, 20 here in this array
$my_cats = array(15, 18, 20);
$my_terms = get_the_terms( get_the_id(), \'category\' );
if ( ! empty( $my_terms ) ) {
if ( ! is_wp_error( $my_terms ) ) {
foreach( $my_terms as $term ) {
if(in_array($term->term_id, $my_cats){
// Display them as you want
echo \'<span>\' . esc_html( $term->name ) . \'</span>\' ;
}
}
}
}