2016-09-26 98 views
0

我想對已經返回的一組帖子運行查詢,我使用$ _GET ['location']從url獲取查詢,現在問題是這個獲得價值可以等於不同meta_values的大量所以我試圖運行下面:在functions.php中的Wordpress查詢

if(isset($_GET['location'])) { 
     $query->set('relation', 'OR'); 
     $query->set('meta_key', 'location_text'); 
     $query->set('meta_compare','LIKE'); 
     $query->set('meta_value', $_GET['location']); 

     $query->set('relation', 'OR'); 
     $query->set('meta_key', 'job_description'); 
     $query->set('meta_compare','LIKE'); 
     $query->set('meta_value', $_GET['location']); 

     $query->set('relation', 'OR'); 
     $query->set('meta_key', 'job_ref'); 
     $query->set('meta_compare','LIKE'); 
     $query->set('meta_value', $_GET['location']); 

} 

但返回的最後一個查詢執行它只返回最後的查詢,以便job_ref - >是這樣甚至可能嗎?

回答

1

看起來像最後一個覆蓋前兩個(不知道)。然而,我認爲以下將工作:

$query->set('meta_query', array(
     'relation' => 'OR', 
     array(
      'key'  => 'location_text', 
      'value' => $_GET['location'], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key'  => 'job_description', 
      'value' => $_GET['location'], 
      'compare' => 'LIKE', 
     ), 
     array(
      'key'  => 'job_ref', 
      'value' => $_GET['location'], 
      'compare' => 'LIKE', 
     ), 
    ) 
) 
相關問題