동일한 키로 여러 메타 키 값을 쿼리하는 방법
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'key1'
AND $wpdb->postmeta.meta_value = 'value1'
// why doesn't this work?
AND $wpdb->postmeta.meta_value = 'value2'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
ORDER BY $wpdb->posts.post_date DESC
";
다음 코드
<?php
$args = array(
'meta_query' => array(
array(
'key' => 'key1',
'value' => 'value1',
'compare' => '='
),
// this array results in no return for both arrays
array(
'key' => 'key1',
'value' => 'value2',
'compare' => '='
)
)
);
$the_query = new WP_Query( $args );
?>
<?php /* Start the Loop */ ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>