xProfile Sortable Column Admin Users Screen

  • Participant
    Level: Initiated
    Posts: 5
    Meagan O’Hara on #35847

    I’m trying to add a sortable column to the Users screen for one of my xProfile fields.

    I have it working but it’s throwing a notice: Notice: Array to string conversion in /srv/www/server/wp-admin/includes/class-wp-users-list-table.php on line 582

    Here is the code I’ve added to a custom plugin:

    // Add the custom column

    function wpmeo_add_user_columns( $column ) 
         $column['Country'] = 'Country';
         return $column;
    add_filter( 'manage_users_columns', 'wpmeo_add_user_columns' );

    // Make the custom column sortable

    function wpmeo_sortable_user_columns( $columns )
        $columns['Country'] = 'country';
        return $columns;
    add_filter( 'manage_users_sortable_columns', 'wpmeo_sortable_user_columns', 10, 3 );

    // Provide the value of the custom column

    function wpmeo_user_columns( $value, $column_name, $id ) 
        if( 'Country' == $column_name ) 
            $new_column = xprofile_get_field_data( 'Country', $id );
            return $new_column;
    add_action( 'manage_users_custom_column', 'wpmeo_user_columns', 10, 3 );

    // Sort the custom column asc & desc

    function my_wpmeo_pre_user_query($user_search)
        global $wpdb, $current_screen;
        // Only filter in the admin
        if ( ! is_admin() )
        // Only filter on the users screen
        if ( ! ( isset( $current_screen ) && 'users' == $current_screen->id ) )
        $vars = $user_search->query_vars;
        if('country' == $vars['orderby'])
            $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='country')"; 
            $user_search->query_orderby = ' ORDER BY UPPER(m1.meta_value) '. $vars['order'];
  • Participant
    Level: Initiated
    Posts: 5
    Meagan O’Hara on #35848

    More info: my BuddyPress field is a select2 dropdown, where my members select their country from an array of options.

    & on top of the Notice & 4 of my 1000+ Users are displaying Array instead of their country.

    There is nothing special about these Users or the countries they have selected. I’m assuming that the issue is the type of field (select2 dropdown) but I don’t know how to modify my my_wpmeo_pre_user_query function accordingly.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #35852

    Hello Meagan,

    Thank you for posting. Please let me know are you using “BuddyPress Xprofile Custom Field Types” by BuddyDev for country field.


You must be logged in to reply to this topic.

This topic is: not resolved