我正在寻找一种搜索方法,让wordpress在WC用户账单/货运公司上搜索匹配项,但我不知道如何实现这一点。我了解了如何使用最常见的用户字段(ID、登录名、电子邮件和nicename)。
搜索常见用户数据:
$customers_query = new WP_User_Query( apply_filters( \'woocommerce_json_search_customers_query\', array(
\'fields\' => \'all\',
\'orderby\' => \'display_name\',
\'search\' => \'*\' . $term . \'*\',
\'search_columns\' => array( \'ID\', \'user_login\', \'user_email\', \'user_nicename\')
) ) );
我也尝试过:
$yoursearchquery = \'Andr\';
$users = new WP_User_Query(array(
\'search\' => $yoursearchquery,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'billing_last_name\',
\'value\' => $yoursearchquery,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'billing_first_name\',
\'value\' => $yoursearchquery,
\'compare\' => \'LIKE\'
)
)
));
但是,只有当我使用希望它搜索的确切单词时,它才会返回,而不是该单词的一部分。
最合适的回答,由SO网友:Annapurna 整理而成
try :
$users = new WP_User_Query(array(
\'s\' => $yoursearchquery,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'billing_last_name\',
\'value\' => $yoursearchquery,
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'billing_first_name\',
\'value\' => $yoursearchquery,
\'compare\' => \'LIKE\'
)
)
));