function wp_get_post_categories( $post_id = 0, $args = array() {}

Retrieve the list of categories for a post.
Compatibility layer for themes and plugins. Also an easy layer of abstraction away from the complexity of the taxonomy layer.


  • int $post_id: Optional. The Post ID.
  • array $args: Optional. Overwrite the defaults.

Source code

function wp_get_post_categories( $post_id = 0, $args = array() ) {

	$post_id = (int) $post_id;

	$defaults = array('fields' => 'ids');

	$args = wp_parse_args( $args, $defaults );

	$cats = wp_get_object_terms($post_id, 'category', $args);

	return $cats;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: