如何在wordpress中使用多查询用户元

时间:2014-06-13 07:54:47

标签: php wordpress

function user_in_query($user_query) {
    global $wpdb;
    $country_value = $_GET['country'];
    $city_value = $_GET['city'];
    $user_query->query_from  .= " JOIN $wpdb->usermeta AS alias ON ($wpdb->users.ID = alias.user_id)";
    $user_query->query_from  .= " JOIN $wpdb->usermeta AS alias2 ON ($wpdb->users.ID = alias2.user_id)";
    $user_query->query_where .= " AND alias.meta_key = 'country' AND alias.meta_value = '".$country_value."'";
    $user_query->query_where .= " AND alias2.meta_key = 'city' AND alias2.meta_value = '".$city_value."'";  
}
add_action('pre_user_query','user_in_query');

当我在网址wp-admin/users.php?country=US&city=Ohio中过滤结果不起作用时,如何解决?

1 个答案:

答案 0 :(得分:0)

我还没有测试过,但我认为pre_user_query是一个过滤器,而不是一个动作。因此,您需要将add_action更改为add_filter,并让您的函数返回$user_query

请,请修复SQL injection漏洞。