我想按自定义 ID 对用户概览列表中的管理列进行排序。为此,我添加了一个函数来对列进行排序,但它没有按预期工作。
它以一种奇怪的方式对字段进行排序。我想还有其他排序或函数有错误?!
这是为用户添加 ID 的代码:
add_action( 'edit_user_profile', 'wcv_store_custom_vendor_id', 0 );
//add_action( 'wcv_admin_after_store_address', 'wcv_store_custom_vendor_id' );
function wcv_store_custom_vendor_id( $user ) {
?>
<table class="form-table">
<tbody>
<tr>
<th><label for="_wcv_custom_vendor_id"><?php _e( 'Vendor ID', 'wcvendors-pro' ); ?></label></th>
<td><input type="text" name="_wcv_custom_vendor_id" id="_wcv_custom_vendor_id" value="<?php echo get_user_meta( $user->ID, '_wcv_custom_vendor_id', true ); ?>" class="regular-text"></td>
</tr>
</tbody>
</table>
<?php
}
// Save the details on the back end when updating the user
add_action( 'wcvendors_update_admin_user', 'save_wcv_custom_vendor_id' );
function save_wcv_custom_vendor_id( $user_id ){
if ( isset( $_POST['_wcv_custom_vendor_id'] ) ) {
update_user_meta( $user_id, '_wcv_custom_vendor_id', $_POST['_wcv_custom_vendor_id'] );
}
这是我到目前为止所拥有的:
// Add column to admin
add_action('manage_users_columns', 'add_custom_vendor_id_column', 10, 1 );
function add_custom_vendor_id_column( $columns ) {
$columns['wcv_custom_vendor_id'] = __('Vendor-ID');
return $columns;
}
// fetching the status, thanks to LoicTheAztec
add_filter('manage_users_custom_column', 'add_data_to_vendor_id_column', 10, 3);
function add_data_to_vendor_id_column( $value, $column_name, $user_id ) {
if ( 'wcv_custom_vendor_id' == $column_name ) {
if( get_user_meta( $user_id, '_wcv_custom_vendor_id', true ) != '' ) {
$value = '<span style="color:green;font-weight:bold;">'.get_user_meta( $user_id, '_wcv_custom_vendor_id', true ).'</span>';
} else {
$value = '<span class="" style="color:red;font-weight:bold;">No ID!</span>';
}
}
return $value;
}
我检查了很多片段,最后一个函数应该按数字排序。但我认为它根本没有影响。
有什么我想念的吗?
qq_花开花谢_0