Codex tools: Log in
Contents |
The function wp_get_post_categories() retrieve a 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.
<?php wp_get_post_categories( $post_id, $args ); ?>
Default $args are:
$defaults = array('fields' => 'ids');
The example below shows how categories are retrieved, and then additional information is retrieved for each category.
$post_categories = wp_get_post_categories( $post_id );
$cats = array();
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
Since: 2.1.0
wp_get_post_categories() is located in wp-includes/post.php.