Forums

Merging and then sorting two categories (1 post)

  1. evandunn
    Member
    Posted 1 year ago #

    So, I want to display the names of all the child categories of a parent's parent category without displaying the parent.

    My solution is to do a get_categories call on each of the two child categories, but the problem is I need them to display in alphabetical order.

    I've tried merging the results of the two get_categories commands, but I can't figure out how to properly sort them by cat_name.

    Here is the code I have right now:

    <?php $args = array( 'child_of' => 10694,);
    $categories = get_categories( $args );
    $args2 = array ('child_of' => 10695,);
    $categories2 = get_categories( $args2 );
    $sortcat = array_merge((array)$categories, (array)$categories2);
    foreach ($sortcat as $category){
    echo "<li><a href='". get_category_link( $category->term_id ) . "'>". $category->cat_name . "</a></li>";}?>

    Can anyone help me with a command that will sort my $sortcat by $category->cat_name?

    Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic