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