0

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?

0
 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, privacy policy and cookie policy

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