Despite lots of documentation and examples online, I'm can't seem to make this simple function work properly. I have no idea what I'm doing wrong, but nonetheless, this isn't working properly. Can anyone spot what I'm missing here?
I'm looking to make a custom Tag Cloud, which is why I'm not using wp_tag_cloud().
$tags = get_tags( array('orderby' => 'name', 'order' => 'ASC'));
foreach($tags as $tag) {
echo "<li><a href=\""
.get_tag_link($tag->term_id)."\">"
.ucwords($tag->name)
."</a> ($tag->count related page)</li>";
}
This produces the following output:
- Black Box (3 related page)
- Waste (2 related page)
- Recycling (2 related page)
- Garbage (1 related page)
- Cheese (1 related page)
- Blue Box (1 related page)
- Test (1 related page)
As you can see, they're sorted by COUNT, and not name. I have no idea why. My arguments seem to be ok. thoughts?
This question is old, but maybe this help someone still searching for answer.
function sortOrder($a, $b) {
if($a->name == $b->name){ return 0 ; }
return ($a->name < $b->name) ? -1 : 1;
}
$tags = get_tags();
usort($tags, 'sortOrder');
foreach($tags as $tag) {
echo "<li><a href=\""
.get_tag_link($tag->term_id)."\">"
.ucwords($tag->name)
."</a> ($tag->count related page)</li>";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With