• Resolved bubbleck

    (@bubbleck)


    Hi there, we are using the member directory to show exhibitors for an event. The event has some exhibitors that pay to be sponsors and therefore we would like them to appear first on the directory. We are displaying the members in alphabetical order by default, but is there a way we can overwrite this for the sponsors to make them come first?

    Many thanks, Caroline

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • @bubbleck

    You can try this code snippet.

    The settings required:
    1. Crete a dropdown field in UM Forms builder with Meta Key is_featured.
    2. Give the dropdown two possible values 0 and 1.
    3. Set the field Privacy to Administrator role only.
    4. As an Administrator edit a User from frontend and set this field value to 1.
    5. Show Members Directory.

    add_filter( 'um_prepare_user_query_args', 'um_custom_prepare_user_query_args', 999999 );
    
    function um_custom_prepare_user_query_args( $args ) {
    
        $args['meta_query'][ ] = array(
            'relation' => 'OR',
                'featured_clause' => array(
                        'key'     => 'is_featured',
                        'value'   => '1',
                        'compare' => '='
                    ),
                'regular_clause'  => array(
                        'key'     => 'is_featured',
                        'value'   => '0',
                        'compare' => '='
                    ),
                'newb_clause'     => array(
                        'key'     => 'is_featured',
                        'compare' => 'NOT EXISTS'
                    )
                );
    
        $args['orderby'] = array(
                        'newb_clause'     => 'ASC',
                        'regular_clause'  => 'ASC',
                        'featured_clause' => 'ASC',
                        'user_login'
                    );
    
        return $args;
    }

    Install the code snippet into your active theme’s functions.php file
    or use the “Code Snippets” plugin.

    https://ww.wp.xz.cn/plugins/code-snippets/

    • This reply was modified 2 years, 7 months ago by missveronica.
    Thread Starter bubbleck

    (@bubbleck)

    Thank you, this is really helpful. I hade to change the following lines to DESC instead of ASC to get the featured profiles to go to the top, but it has worked.

                        'featured_clause' => 'DESC',
                    'newb_clause'     => 'DESC',

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Member Directory Order’ is closed to new replies.