Get array of current post term ID’s

I’m creating a little “Related posts” section on a site and I’m doing it based on terms in a custom taxonomy called “director”.

How can I get an array of term ID’s for the current post so that I can use them in a custom WP_Query array?

1 Answer
1

To get the attached term IDs, use get_the_terms() and wp_list_pluck():

if ( $terms = get_the_terms( $post, 'director' ) ) {
    $term_ids = wp_list_pluck( $terms, 'term_id' );
}

Leave a Comment