Function: wp_get_post_categories

wp_get_post_categories( integer $post_id, array $args )

Retrieve the list of categories for a post.

Shortcut: wgpc

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

Compatibility layer for themes and plugins. Also an easy layer of abstraction away from the complexity of the taxonomy layer.

Parameters

Name Type(s) Default Value Description
$post_id integer

Optional. The Post ID. Does not default to the ID of the global $post. Default 0.

$args array array()

Optional. Category query parameters. Default empty array. See WP_Term_Query::__construct() for supported arguments.

Returns

array | WP_Error

List of categories. If the $fields argument passed via $args is 'all' or 'all_with_object_id', an array of WP_Term objects will be returned. If $fields is 'ids', an array of category ids. If $fields is 'names', an array of category names. WP_Error object if 'category' taxonomy doesn't exist.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.