2016-02-17 41 views
0

我需要一些幫助才能使wp_user_query工作;一直在掙扎,嘗試很多東西,但無法使其正常工作。需要關於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. 顯示,其中由meta_value其中lawyer_location =倫敦
  3. 訂單meta_keymeta_key = lawyer_numeric_rank以ASC順序

我試過這個但不能得到這個工作,既在倫敦的位置上進行篩選,也按排名排序...

該代碼現在在位置上進行篩選;但順序部分不工作;如果我從此刪除位置過濾器;然後orderby確實工作...

我希望有人可以幫助這一點。

+1

您將用於比較'lawyer_location'和'London'的子數組沒有密鑰。 – phaberest

+0

感謝評論phaberest,但這是我的子陣列中的第一項; 'key'=>'lawyer_location', –

+0

不是說你錯了,但那是我所看到的。謝謝 –

回答

1

您正在錯誤地形成元查詢參數。下面的代碼也可以幫助你進行更多的元查詢。

$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' => '=', 
         ), 
      ), 


     */ 

    ) 
); 
相關問題