需要帮助wp_user_query不起作用


Need assistance with wp_user_query not working

我需要一些帮助才能让wp_user_query工作;一直在挣扎并尝试了很多东西,但无法让它以正确的方式工作。

这是我的代码:

$args = array(
    'meta_query' => array(
        'role'     => 'personal-injury-lawyer',
        'orderby'  => 'meta_value',
        'meta_key' => 'lawyer_numeric_rank',
        'order'    => 'ASC',
        array(
            'key'     => 'lawyer_location',
            'value'   => 'London',
            'compare' => '='
        ),
    )
);
$london_user_query = new WP_User_Query($args);  
if ( ! empty($london_user_query->results)) {
    foreach ( $london_user_query->results as $user ) {

我知道foreach循环不是闭合的;只是试图缩短这个......

我正在尝试对此查询做三件事:

  1. 显示personal-injury-lawyer的角色
  2. 显示lawyer_location字段meta_key = 伦敦
  3. 的位置
  4. meta_value排序,其中 meta_key = ASC 顺序中的lawyer_numeric_rank

我已经尝试了多种方法,但无法让它既可以过滤伦敦位置,也可以按排名排序......

现在的代码确实按位置过滤; 但是 orderby 部分不起作用; 如果我从中删除位置过滤器; 那么 orderby 确实有效...

我希望有人能帮忙。

您错误地形成了元查询参数。下面的代码也应该可以帮助您进行更多的元查询。

$args = array(
    'role'=> 'personal-injury-lawyer', //assuming you have created a role that corresponds..
    'order' => 'ASC',
    'orderby' => 'meta_value',
    'meta_key' => 'lawyer_numeric_rank',  
    'meta_query' => array(
      // 'relation'=> 'AND', --> if you want more conditions 
        array(
            'key'     => 'lawyer_location',
            'value'   => 'London',
            'compare' => '='
        ),
       /* even more conditions with OR, cumulative effect is match lawyer location AND 1 of the nested arrays

            array(
                        'relation' => 'OR',
                        array(
                                'key' => '',
                                'value' => '',
                                'compare' => '=',
                        ),
                        array(
                                'key' => '',
                                'value' => '',
                                'compare' => '=',
                        ),
            ),

       */
    )
);