WordPress-使用自定义字段(ACF)过滤管理员用户列表 [英] Wordpress - filter admin user list with custom field (ACF)
问题描述
我想通过以下方式扩展用户列表的视图:
I want to extend my view of users list by:
- 根据自定义字段添加可排序的列
- 可以通过自定义字段过滤列表
所以我做了什么:
- 通过ACF创建了自定义字段(名称为:opiekun_klienta)
- 通过用户设置输入了适当的值(因此我选择了一个清单中的值)
我有一段代码:
add_filter( 'manage_users_columns', 'column_register_wpse_101322' );
add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 );
function column_register_wpse_101322( $columns )
{
$columns['accountmanager_col'] = 'Opiekun';
return $columns;
}
function column_display_wpse_101322( $empty, $column_name, $opiekunklienta )
{
$opiekunklienta = get_field( "opiekun_klienta" );
if ( 'accountmanager_col' != $column_name )
return $empty;
return "<strong>$opiekunklienta</strong>";
该代码添加了列,但未显示任何值。代码中的错误在哪里?我找不到它..最重要的是,我想创建一个dropdown + submit按钮来过滤列表(因此该下拉列表将显示自定义字段的值。我不知道从哪里开始。.
the code adds column but there are no values displayed. Where is the mistake in the code? i cannot find it.. on top of that I would like to create a dropdown+submit button to filter the list in general (so the dropdown will display values of the custom field. I have no clue where to start with it..
感谢任何提示!
推荐答案
更新的代码:
add_filter('manage_users_columns','column_register_wpse_101322');
add_filter( 'manage_users_columns', 'column_register_wpse_101322' );
add_filter('manage_users_custom_column','column_display_wpse_101322',10, 3);
add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 );
function column_register_wpse_101322( $columns )
{
$columns['accountmanager_col'] = 'Opiekun';
return $columns;
}
function column_display_wpse_101322( $post_id, $column_name, $opiekunklienta )
{
$opiekunklienta_code = get_user_meta( $opiekunklienta,'opiekun_klienta',true);
if ( 'accountmanager_col' != $column_name )
return $empty;
return "<strong>$opiekunklienta_code</strong>";
}
这篇关于WordPress-使用自定义字段(ACF)过滤管理员用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!