您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取文章所属标签对象函数:wp_get_post_tags

时间:2024-03-12

WordPress函数wp_get_post_tags根据文章ID获取该文章的标签对象,返回数据中包含了标签的ID、名称、别名等信息。

wp_get_post_tags( int $post_id, array $args = array() )

函数参数

$post_id

整数

文章的ID

$args

数组

标签查询参数,可用值参考get_categories()函数的$args参数说明

函数返回值

Array
(
    [0] => WP_Term Object
        (
            [term_id] => 10
            [name] => WP函数
            [slug] => wordpress-functions
            [term_group] => 0
            [term_taxonomy_id] => 10
            [taxonomy] => post_tag
            [description] => 
            [parent] => 0
            [count] => 101
            [filter] => raw
        )

)

函数使用示例

$post_tags = wp_get_post_tags(3699);
foreach($post_tags as $tag) {
	echo '<li><a href="' . esc_url(get_tag_link($tag->term_id)) . '">' . $tag->name . '</a></li>';
}

扩展阅读

wp_get_post_tags()函数位于:wp-includes/post.php

相关函数:

  • wp_get_post_terms()

  • wp_get_object_terms()

  • wp_get_post_categories()

  • get_category()

  • wp_set_post_tags()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 21329.com


Whatsapp
Powered by RRZCMS