So I have bunch of custom posts & IDs (coming from ACF Fields). and I want to get all categories of those posts. is there any way we can get all unique categories from array of post IDs?

1 Answer 1

 global $wpdb;
 $post_ids = [1,2,3] //Array of all post ids

// get all category id's based on post ids
$result = $wpdb->get_results( " select term_taxonomy_id from " . $wpdb->prefix . "term_relationships where object_id in (implode(",",$post_ids)) );

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.