2016-09-26 33 views
0

私はすでに返された一連の投稿に対してクエリを実行しようとしていますが、今は$ _GET ['location']を使ってURLからクエリを取得しています私は以下を実行しようとしているので、値が異なるmeta_valuesの多数を等しくすることができGET: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

最後のものが最初の2つをオーバーライドするように見えます(わかりません)。しかし、私は次のように動作します:

$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', 
     ), 
    ) 
) 
関連する問題