たくさん
$params = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes_feat',
'posts_per_page' => 5
);
$wc_query = new WP_Query($params);
global $post, $product;
if ($wc_query->have_posts()) {
// i am only trying to print products with meta_value = yes_feat
// but if the statement above is true it prints all products
echo "print products that have meta_value = yes_feat";
}
else
{
echo "nothing found";
}
おかげで、あなたのコードWP_Query引数に
<?php
$params = array(
'post_type' => 'product',
'meta_query' => array(
array('key' => '_featured', //meta key name here
'value' => 'yes_feat',
'compare' => '=',
)
),
'posts_per_page' => 5
);
$wc_query = new WP_Query($params);
global $post, $product;
if($wc_query->have_posts()) {
while($wc_query->have_posts()) {
$wc_query->the_post();
$wc_query->post_name;
echo "print products that have meta_value = yes_feat";
$yes_feat = get_post_meta($wc_query->ID, '_featured',true);
} // end while
} // end if
else
{
echo "nothing found";
}
wp_reset_postdata();
?>
をメタクエリを追加し、OKのようです。追加の要因がなければ、すべての製品を提供することはできません。このコードでは、最後のクエリをhave_postsの中に出力し、ここに結果を貼り付けて貼り付けます。 $ i = 0; if($ wc_query-> have_posts()){$ i ++; if($ i == 1)var_dump($ wc_query-> query); } –