• After updating the WordPress install of a client of mine we saw that the get_categories() function for some reason kept returning everything in alphabetic order. On a normal blog that may not be a problem, but since the main-categories were area’s in the Netherlands and the subcategories were places in those area’s that gave a very weird result (so, all categories were in alphabetic order, sub and main categories were mixed).
    I did have hierarchical set to 1, even copied the word from the codex to be sure I didn’t make a typing error, but the results were the same: no hierarchical list but an alphabetic list.

    An example:

    • Amsterdam
    • Buitenveldert
    • IJburg
    • Watergraafsmeer
    • Zeeburg
    • Surrounding Area’s
    • Almere
    • Badhoevedorp
    • Vinkenveen
    • Zaandam

    The above is what we wanted to get (and the indenting etc. was done by other HTML, the indenting etc. above is just to show which categories are main/sub categories).
    This is what we got:

    • Almere
    • Amsterdam
    • Badhoevedorp
    • Buitenveldert
    • IJburg
    • Surrounding Area’s
    • Vinkenveen
    • Watergraafsmeer
    • Zaandam
    • Zeeburg

    I had to add a function to functions.php and call that per main category in order to make it display as we wanted.

    Are there more people having issues like this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi illutic,

    I have exactly the same problem: after upgrading to 2.8.4 my main and sub categories got mixed and appeared in alphabetical order. Apart from that the My Category Order isn’t working at all, but that’s another plugin so another topic I guess (I get a completely white screen when I activate the My Category Order, even after re-installing it).

    I would love to hear which function you added to functions.php and what you mean exactly by calling it per main category… (I’m not a programmer so if you can write it down more detailed I would be pleased :)) Still wondering why every WP upgrade always comes with plugin problems…

    Thread Starter Hiranthi

    (@illutic)

    What I added to functions.php:

    function displayPosts( $id )
    {
    	$cat = get_category($id, OBJECT);
    
    	echo '<p><a href="'.get_category_link( $id ).'">'.$cat->cat_name.'</a> <small> ('.$cat->category_count.' ' . ($cat->category_count == 1 ? 'post' : 'posts') . ')</small>';
        if ($cat->category_description != '')
    	{
        	echo '<br />'.$cat->category_description . ' <a href="'.get_category_link( $id ).'">View posts &raquo;</a>';
        }
        echo '</p>';
    
    	/* subcategories */
    	$args = array(
    					'type'			=> 'post',
    					'child_of'		=> $id
    				);
        foreach (get_categories($args) as $cat)
    	{
        	echo '<p><span class="subcategory">';
    
            echo '<a href="'.get_category_link( $cat->cat_ID ).'">'.$cat->cat_name.'</a> <small> ('.$cat->category_count.' ' . ($cat->category_count == 1 ? 'post' : 'posts') . ')</small>';
            if ($cat->category_description != '')
    		{
            	echo '<br />'.$cat->category_description . ' <a href="'.get_category_link( $cat->cat_ID ).'">View posts &raquo;</a>';
            }
    
    		echo '</span></p>';
    	} // end foreach
    } // end displayPosts

    With that function you’ll have to manually add this per main-category in a template (ie. displayPosts( 4 ); displayPosts( 6 ); etc.).

    I haven’t had any problems with the My Category Order and upgrading to WP2.8.4 (not that I remember anyway).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_categories alphabetic order, no matter what’ is closed to new replies.