我希望添加自定义筛选器,其中包含来自users表的自定义列,而不是metaKey。我发现这个函数可以通过metaKey进行过滤:
add_filter('pre_get_users', 'filter_users_by_job_role_section');
function filter_users_by_job_role_section($query)
{
global $pagenow;
if (is_admin() && 'users.php' == $pagenow) {
// figure out which button was clicked. The $which in filter_by_job_role()
$top = $_GET['job_role_top'];
$bottom = $_GET['job_role_bottom'];
if (!empty($top) OR !empty($bottom))
{
$section = !empty($top) ? $top : $bottom;
// change the meta query based on which option was chosen
$meta_query = array (array (
'key' => 'membership_user_role',
'value' => $section,
'compare' => 'LIKE'
));
$query->set('meta_query', $meta_query);
}
}
}
我希望将查询更改为使用comumn表"user_status“。我该怎么做呢?
发布于 2019-10-07 15:54:38
自定义表列不可能使用<#>This,您应该避免并避免对WP表的自定义修改。相反,将这些数据存储在用户元中而不是自定义表列中。
当您下次更新WordPress时,如果数据库模式将更改,WP将调整表以匹配,销毁自定义列及其包含的所有数据(否则更新将失败)。
您试图使用的API用于这些用户元值,您可以像post元一样调整用户元:
add_user_meta
update_user_meta
get_user_meta
delete_user_meta
您可以通过使用这些代码来简化代码,它将允许您消除调整表和保存/获取信息所需的原始SQL,并允许您按预期使用WP。
请记住,永远不要修改WP Core以更改WP,其中包括表列。
https://wordpress.stackexchange.com/questions/349941
复制相似问题