[Support request] Order of categories

Home Forums Support [Support request] Order of categories

Home Forums Support Order of categories

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1558999
    ETO
    // 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?

    #1559370
    Leo
    Staff
    Customer Support

    Hi there,

    The theme itself does not control the WordPress posts loop.

    An article like this might help:
    https://codex.wordpress.org/Alphabetizing_Posts

    #1559827
    ETO

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

    #1561218
    Tom
    Lead Developer
    Lead Developer

    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 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.