Site logo

Archived topic

Order of categories

3 replies · Started by ETO on November 30, 2020

Viewing posts 1–4 of 4
// list subcategories...
function wpse_filter_child_cats( $query ) {

if ( $query->is_category ) {
    $queried_object = get_queried_object();
    $child_cats = (array) get_term_children( $queried_object->term_id, 'category' );

    if ( ! $query->is_admin )
        //exclude the posts in child categories
        $query->set( 'category__not_in', array_merge( $child_cats ) );
    }

    return $query;
}
add_filter( 'pre_get_posts', 'wpse_filter_child_cats' );

Hello,
I use the above code to list the subcategories on parent category pages. But it does not list the categories in alphabetical order. Can you change this code for me so that it can list the subcategories alphabetically?

Hi, Leo!
I am not talking about ordering posts but ordering subcategories.

Hi there,

I don't have a ton of experience with this, but this is the perfect question for a site like this: https://wordpress.stackexchange.com/

If you post the same question with the example, someone should have an idea :)

This archived topic is closed to new replies.