简体   繁体   中英

get all tags of published posts Wordpress

How do I fetch all tag names (with ID and count) from all published posts?

I know there is wp_tag_cloud but I only want an array of all tags.

Check out get_terms() to retrieve the terms in a given taxonomy:

http://codex.wordpress.org/Function_Reference/get_terms

Examples:

$categories = get_terms( 'category',    'orderby=count&hide_empty=0' );

$tags       = get_terms( 'post_tag',    'orderby=count&hide_empty=0' );

$myterms    = get_terms( 'my_taxonomy', 'orderby=count&hide_empty=0' );

This works for me along with tags count.

<?php
$tags = get_tags();
if ($tags) {
?><ul class="tags"><?php
foreach ($tags as $tag) {
    echo '<li><a href="' . get_tag_link( $tag->term_id ) . '" 
          title="' . sprintf( __( "View all posts in %s" ), $tag-
          >name ) . '" ' . '>' . $tag->name.' (' . $tag->count . ')</a></li>';
}
echo '<li><a href="#">View All</a><span class="arrow"></span>
</li>'; ?></ul>
<?php }?>   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM