• Hi!
    I have a directory, with tags and filters all working.

    What I want is the ability to reverse the sorting.

    Right now, I am sorting via “Nickname” so that users can keep usernames separate.

    But I want to be able to flip the sort from A-Z to Z-A.

    Anyone deal with this?

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @brianol

    You can try the following code snippet to add A-Z / Z-A sorter. Ensure that the “Enable custom sorting” is checked in the Member Directory Settings > Sorting section for this to work:

    add_filter("um_member_directory_pre_display_sorting","um_031022_custom_sorting_option");
    function um_031022_custom_sorting_option( $options ){
        $options['sort_az'] = "A-Z";
        $options['sort_za'] = "Z-A";
        
        return $options;
    }
    
    add_filter("um_modify_sortby_parameter","um_031022_sortby_parameter", 10, 2 );
    function um_031022_sortby_parameter( $query_args, $sortby ){
        
        if( "sort_az" == $sortby ){
            $query_args['orderby'] = array( 'user_login' => 'ASC' );
        }else if( "sort_za" == $sortby ){
            $query_args['orderby'] = array( 'user_login' => 'DESC' );
        }
    
        return $query_args;
    }

    You can add the code to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code.

    Regards,

    Thread Starter brianol

    (@brianol)

    OK, I have added this snippet. I’ve cleared cache and enabled custom filtering.

    But I don’t know where to change this.

    If I am honest, what I want is to be able to sort that one list in particular in a random order, with a sort field, much like pages and posts have a sort order for navigation.

    Thread Starter brianol

    (@brianol)

    OK, I see where we added the A-Z… that’s not quite what I meant. That sorts the directory list A-Z/Z-A.

    I want to sort the order of the tags as they appear in the dropdown.

    see this: screenshot

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @brianol

    I’ve manually sorted the Age Brackets to the Profile Form > Age Bracket’s field settings. When I filled users with the Age Brackets, it automatically sorts them based on the sort done in the Profile Form.

    Infant/Toddler | 0 - 2 years old
    Preschooler | 3 - 5 years old
    Child | 6 - 10 years old
    Youth/Teen | 11 - 17 years old
    Adult | 18 years old +

    Here’s a screenshot:
    https://drive.google.com/file/d/1BtRdMw3YCRodZaQ6OgcDQgXa3eiS4SSI/view?usp=sharing

    Regards,

    Thread Starter brianol

    (@brianol)

    OK, I’m missing a piece.
    See screenshots.

    1. Code Snippet added to functions
    2. custom sorting on

    the Custom sorting A-Z returns no results (i’m sorting by nickname, so that may be the problem)

    I have no options in the user tags field options?

    https://drive.google.com/file/d/1L1hEcl45-RX1sBfbA88CTfmNTE7dyNBl/view?usp=sharing, https://drive.google.com/file/d/1YNgNU4qUKD_P6W3J4xoxG_2sHCz-t_dX/view?usp=sharing, https://drive.google.com/file/d/1_ATNm8CXLGXUh4m5evSUrr7MB7OEZ0pE/view?usp=sharing, https://drive.google.com/file/d/1wVgPyCRfDbQ06oW_TXIfd3-K5JHUJkpb/view?usp=sharing

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @brianol

    Please replace the above code with the following:

    add_action("init", function(){
        if( class_exists( 'UM_User_Tags' ) ){
            remove_filter( 'um_member_directory_filter_select_options_sorted', array( UM()->User_Tags()->member_directory(), 'user_tags_filter_options_sort' ), 10, 2 );
        }
    });

    The above code will disable the automatic sort for the User Tags filter. Ensure that the order is correctly set in the WP Admin > Ultimate Member > User Tags.

    Regards,

    Thread Starter brianol

    (@brianol)

    How do you set the sort order here: WP Admin > Ultimate Member > User Tags? I don’t have any sort fields.

    https://drive.google.com/file/d/1_CcpVYTqs5HIIpTlvUfM591ZxI98guOS/view?usp=sharing

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @brianol

    We have the same order of Age Brackets options and it perfectly follows the order of the options as a filter in the Member Directory. Did you try using the new code snippet?

    Regards,

    Thread Starter brianol

    (@brianol)

    Hi @champsupertramp,
    yes I added the snippet. It seems to display tags in the order they were added now.

    (I edited and resaved the “age” list)

    the “sport category list is now not A-Z…

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @brianol

    Sorry for the late response.

    Is the Sports Category created via UM User tags?

    Thread Starter brianol

    (@brianol)

    Yes everything is created using User Tags.

    I had to remove the code snippets though. When I added the code snippets in, they become sorted by “date edited” and therefore where no longer a-z. I could beak the system simply by editing them in order, but that’s not a long term solutions.

    For now I’ve kind of put this aside. It would be cool if you could just edited the “sort” number like wordpress pages and posts.

    Thanks

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘As Sorting toggle to Directory Z-A/A-Z’ is closed to new replies.