Support » Fixing WordPress » get_categories() not showing up in ID order

  • I am having trouble with some specialty code I had written by a programmer a couple of years ago. Since upgrading to WordPress 2.8, this code is not working properly.

    Each category in my blog is a book chapter. Each post is a page of the book. The sidebar is supposed to list the categories in ID order, and under each category, the posts in forward chron order. There is some cookie-related code that precedes the code I’m showing here, to keep it so that your table of contents only goes up through the next post. (Users read in forward-chron, not reverse-chron, order, on this particular blog/book.)

    This was working fine through 2.7, I think. But now, the list of categories is in alphabetical order, not ID order, and I can’t figure out why. I have double-checked to make sure that in various upgrades etc. that the IDs of the categories haven’t changed — if the list was in ID order, it would be correct, but it’s in name order, which is wrong. (you can see the sidebar at work here: ).

    I’m afraid that I don’t have enough PHP smarts to figure out why this isn’t working or even come up with the simplest troubleshooting. I’d be most appreciative if you could take a look and lend a hand or point me in the right direction.

    Thanks so much.

    <?php foreach ( get_categories('orderby=ID') as $category ) : ?>
    		<h3><?php echo wp_specialchars($category->cat_name); ?></h3>
    			<?php $posts = get_posts("category={$category->cat_ID}&orderby=post_name&order=ASC&numberposts=20");
    			foreach ($posts as $post) : setup_postdata($post); ?>
    			<div class="post">
    					<p id="post-<?php the_ID(); ?>" style="padding-top:0px;padding-bottom:0px;margin-top:0px;margin-bottom:0px;"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
    					<?php foreach ((array) get_post_custom_values('Episode') as $nvepisode) { $printepisode = $nvepisode; } ?><?php echo "$nvepisode : "; ?>
    					<?php the_title(); ?>
    		<?php endforeach; endforeach; ?></ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

    The code you posted above looks correct. The important line is:

    <?php foreach ( get_categories('orderby=ID') as $category ) : ?>

    which is fetching the site’s categories in ID order.

    Do you have any plugins installed? Have you tried deactivating all of them to see if that makes any difference to the listing? If it does, re-activate the plugins one by one – checking the listing after each re=activation – until you find the problematic plugin(s).

    Thanks so much for the troubleshooting advice, esmi, I’ll take it and report back.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_categories() not showing up in ID order’ is closed to new replies.