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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.