wp_get_post_terms

The timeline below displays how wordpress function wp_get_post_terms has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.7

/**
 * Retrieves the terms for a post.
 *
 * @since 2.8.0
 *
 * @param int             $post_id  Optional. The Post ID. Does not default to the ID of the
 *                                  global $post. Default 0.
 * @param string|string[] $taxonomy Optional. The taxonomy slug or array of slugs for which
 *                                  to retrieve terms. Default 'post_tag'.
 * @param array           $args     {
 *     Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments.
 *
 *     @type string $fields Term fields to retrieve. Default 'all'.
 * }
 * @return 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.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.9

/**
 * Retrieves the terms for a post.
 *
 * @since 2.8.0
 *
 * @param int          $post_id  Optional. The Post ID. Does not default to the ID of the
 *                               global $post. Default 0.
 * @param string|array $taxonomy Optional. The taxonomy slug or array of slugs for which
 *                               to retrieve terms. Default 'post_tag'.
 * @param array        $args     {
 *     Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments.
 *
 *     @type string $fields Term fields to retrieve. Default 'all'.
 * }
 * @return 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.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.8

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * wp_get_object_terms().
 *
 * @since 2.8.0
 *
 * @param int    $post_id  Optional. The Post ID. Does not default to the ID of the
 *                         global $post. Default 0.
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @param array  $args     Optional. Term query parameters. Default empty array.
 *                         See WP_Term_Query::__construct() for supported arguments.
 * @return 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.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.6

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * wp_get_object_terms().
 *
 * @since 2.8.0
 *
 * @param int    $post_id  Optional. The Post ID. Does not default to the ID of the
 *                         global $post. Default 0.
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @param array  $args     Optional. wp_get_object_terms() arguments. Default empty array.
 * @return array|WP_Error  List of post terms or empty array if no terms were found. WP_Error object
 *                         if `$taxonomy` doesn't exist.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.3

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @since 2.8.0
 *
 * @param int    $post_id  Optional. The Post ID. Does not default to the ID of the
 *                         global $post. Default 0.
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @param array  $args     Optional. {@link wp_get_object_terms()} arguments. Default empty array.
 * @return array|WP_Error  List of post terms or empty array if no terms were found. WP_Error object
 *                         if `$taxonomy` doesn't exist.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.1

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @since 2.8.0
 *
 * @param int    $post_id  Optional. The Post ID. Does not default to the ID of the
 *                         global $post. Default 0.
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @param array  $args     Optional. {@link wp_get_object_terms()} arguments. Default empty array.
 * @return array List of post tags.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 4.0

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @since 2.8.0
 *
 * @uses wp_get_object_terms()
 *
 * @param int    $post_id  Optional. The Post ID. Does not default to the ID of the
 *                         global $post. Default 0.
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @param array  $args     Optional. {@link wp_get_object_terms()} arguments. Default empty array.
 * @return array List of post tags.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 3.9

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @since 2.8.0
 *
 * @uses wp_get_object_terms() Gets the tags for returning. Args can be found here
 *
 * @param int $post_id Optional. The Post ID
 * @param string $taxonomy The taxonomy for which to retrieve terms. Defaults to post_tag.
 * @param array $args Optional. Overwrite the defaults
 * @return array List of post tags.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}

WordPress Version: 3.7

/**
 * Retrieve the terms for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @package WordPress
 * @subpackage Post
 * @since 2.8.0
 *
 * @uses wp_get_object_terms() Gets the tags for returning. Args can be found here
 *
 * @param int $post_id Optional. The Post ID
 * @param string $taxonomy The taxonomy for which to retrieve terms. Defaults to post_tag.
 * @param array $args Optional. Overwrite the defaults
 * @return array List of post tags.
 */
function wp_get_post_terms($post_id = 0, $taxonomy = 'post_tag', $args = array())
{
    $post_id = (int) $post_id;
    $defaults = array('fields' => 'all');
    $args = wp_parse_args($args, $defaults);
    $tags = wp_get_object_terms($post_id, $taxonomy, $args);
    return $tags;
}