Function: wp_get_post_terms

wp_get_post_terms( integer $post_id, string | array $taxonomy, array $args )

Retrieves the terms for a post.

Shortcut: wgpt

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.

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.

$taxonomy string | array 'post_tag'

Optional. The taxonomy slug or array of slugs for which to retrieve terms. Default 'post_tag'.

$args array array()

{ Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments.

@type string $fields Term fields to retrieve. Default 'all'.

}

Returns

array | WP_Error

Array of WP_Term objects on success or empty array if no terms were found. WP_Error object if $taxonomy doesn't exist.

WordPress Developer Newsletter

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