2013-11-23 6 views
1

나는 wordpress에서 쿼리를 성공적으로 실행하고 있습니다. 쿼리는 다음과 같습니다.단일 쿼리 (메타 데이터)의 다중 메타 키 및 메타 값

SELECT wp_posts.*, wp_postmeta.meta_value 
FROM wp_posts, wp_postmeta, wp_term_relationships, wp_terms 
WHERE term_id = '12' 
    AND term_taxonomy_id = '12' 
    AND ID = post_id 
    AND ID = object_id 
    AND post_type = 'property' 
    AND post_status = 'publish' 
    AND meta_key = 'property_amount' 
    AND replace(replace(meta_value, ',', ''), '"', '') >= 1 
GROUP BY wp_posts.ID 
ORDER BY replace(replace(meta_value, ',', ''), '"', '') DESC LIMIT 0, 10 

하지만 한 번 더 meta_key 위 쿼리에서 값 조건을 추가 할 그래서 난이

SELECT wp_posts.*, wp_postmeta.meta_value 
FROM wp_posts, wp_postmeta, wp_term_relationships, wp_terms 
WHERE term_id = '12' 
    AND term_taxonomy_id = '12' 
    AND ID = post_id 
    AND ID = object_id 
    AND post_type = 'property' 
    AND post_status = 'publish' 
    AND ((wp_postmeta.meta_key = 'property_amount' 
     AND wp_postmeta.meta_value) >= '1' 
     AND (wp_postmeta.meta_key = 'property_land_type' 
     AND wp_postmeta.meta_value IN ('H', 'C'))) 
GROUP BY wp_posts.ID 

다음 줄에 내 쿼리 변경은 첫 번째 쿼리에 추가입니다

meta_key="property_land_type" and meta_value in ('L','H','C') 

하지만 작동하지 않습니다. 이 쿼리를 기반으로하는 다른 많은 쿼리가 있으므로 WP_Query를 작성할 수 없습니다.

미리 감사드립니다.

+0

대신 "이 작동하지 않습니다"의 구체적 수 있습니까? 정확히 작동하지 않는 것은 무엇입니까? –

+0

이미 질문을 받고 대답하셨습니까? http://stackoverflow.com/questions/20160027/meta-key-and-meta-value-query-in-wordpress –

답변

0

독자적인 쿼리를 추가하지 않고도 WordPress 쿼리를 확장 해보십시오. 다음 코드를 사용자 정의 할 수 있습니다,

$args = array(
    'post_type' => 'property', 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'order' => 'ASC', 
    'meta_query' => array(
     array(
      'key' => 'property_amount', 
      'value' => '1', 
      'compare' => 'LIKE', 
     ), 
     array(
      'key' => 'property_land_type', 
      'value' => 'L', 
      'compare' => 'LIKE', 
     ) 
    ) 
); 

$query = new WP_Query($args); 
0
$args = array(
    'post_type' => 'property', 
    'post_status' => 'publish', 
    'posts_per_page' => 10, 
    'order' => 'ASC', 
    'meta_query' => array(
     array(
      'key' => 'property_amount', 
      'value' => '1', 
      'compare' => '=', 
     ), 
     array(
      'key' => 'property_land_type', 
      'value' => array('L','H','C'), 
      'compare' => 'IN', 
     ) 
    ) 
); 

$query = new WP_Query($args); 

if ($query->have_posts()) : 
    while ($query->have_posts()) : $query->the_post(); 
      echo $post_id = get_the_ID(); 
    endwhile; 
endif; 
관련 문제