• Hello everyone,

    Any idea to sort tags alphabetically like this page?

    I wrote code below but I think it’s a beat heavy:

    <?php
    $tags = wp_tag_cloud( $args = array('smallest'=>22, 'largest'=>22, 'format'=>'array') );
    		foreach ($tags as $num => $tag) {
    			$st = strip_tags($tag);
    			$substr = substr($st, 0, 1);
    			switch ($substr) {
    				case 'a' : $arr[$tag] = $substr;
    				case 'b' : $arr[$tag] = $substr;
    				case 'c' : $arr[$tag] = $substr;
    				case 'd' : $arr[$tag] = $substr;
    				case 'e' : $arr[$tag] = $substr;
    				case 'f' : $arr[$tag] = $substr;
    				case 'g' : $arr[$tag] = $substr;
    				case 'h' : $arr[$tag] = $substr;
    				case 'i' : $arr[$tag] = $substr;
    				case 'j' : $arr[$tag] = $substr;
    				case 'k' : $arr[$tag] = $substr;
    				case 'l' : $arr[$tag] = $substr;
    				case 'm' : $arr[$tag] = $substr;
    				case 'n' : $arr[$tag] = $substr;
    				case 'o' : $arr[$tag] = $substr;
    				case 'p' : $arr[$tag] = $substr;
    				case 'q' : $arr[$tag] = $substr;
    				case 'r' : $arr[$tag] = $substr;
    				case 's' : $arr[$tag] = $substr;
    				case 't' : $arr[$tag] = $substr;
    				case 'u' : $arr[$tag] = $substr;
    				case 'v' : $arr[$tag] = $substr;
    				case 'w' : $arr[$tag] = $substr;
    				case 'x' : $arr[$tag] = $substr;
    				case 'y' : $arr[$tag] = $substr;
    				case 'z' : $arr[$tag] = $substr;
    			}
    
    		}

    I tried to sort tags in different arrays. Is it right?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try to put your tags first in an array and try something like ‘array_sort’ PHP function.

    I think with some googling you can find many examples of how to sort more effectively.

    Thread Starter liberto_io

    (@liberto_io)

    Look, in my code $tags is an array that WordPress generated like this:

    $tags = array([0]=>Alex [1]=>Mat [2]=>Michael [3]=>Peter);

    I want to turn this array to something like this:

    $tags = array([a]=>Alex [m]=>Mat [m]=>Michael [p]=>Peter);

    [ Please do not bump, that’s not permitted here. ]

    @liberto_lo – did you ever get this resolved?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort tags alphabetically’ is closed to new replies.