我正在尝试使用WP User query构建一个查询,可以在其中进行搜索
这是我的参数:
$args = array(
\'role\' => \'author\',
\'number\' => $limit,
\'offset\' => $offset,
\'order\' => $order_sort,
\'orderby\' => $order_by,
\'search\' => \'*\'.esc_attr( $search_str ).\'*\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'reg_complete\',
\'value\' => 1,
\'compare\' => \'=\',
),
array(
\'relation\' => \'OR\',
array(
\'key\' => \'first_name\',
\'value\' => $search_str,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'last_name\',
\'value\' => $search_str,
\'compare\' => \'LIKE\'
)
),
)
);
如果搜索名字/姓氏,工作正常。。。但名字/电子邮件不匹配
知道怎么解决吗?
编辑:从参数中删除search\\u列并添加此筛选器:
add_filter( \'user_search_columns\', \'my_user_search_columns\', 10, 3 );
function my_user_search_columns( $search_columns, $search, $this ) {
$search_columns[] = \'user_email\';
$search_columns[] = \'user_nicename\';
return $search_columns;
}
更改前的结果相同