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.
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
$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 }?>