Get_tags () function not sorting correctly

Despite the many documents and examples on the Internet, I cannot get this simple function to work properly. I have no idea what I'm doing wrong, but nonetheless, this is not working properly. Can anyone determine what I am missing here?

I want to create a custom label cloud, so I do not use 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 leads to the following conclusion:

 - 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 are sorted by COUNT, not by name. I have no idea why. My arguments seem to be in order. thoughts?

+3
source share
2 answers

This question is old, but maybe it will help someone else find the 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>";    
    }
+1
source

, ... , ( "orderby" "orderby" ). -, .

, , . , , .

0

Source: https://habr.com/ru/post/1784180/


All Articles