Php 伍因斯托克阿格斯酒店
我有下面的代码行,但它不工作 是否有人不知道只展示instock产品的正确方式 我在谷歌上找不到任何东西Php 伍因斯托克阿格斯酒店,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有下面的代码行,但它不工作 是否有人不知道只展示instock产品的正确方式 我在谷歌上找不到任何东西 $args = array( 'posts_per_page' => 4, 'post_type' => 'product','meta_key' => '_featured','meta_value' => 'instock','orderby' =>'rand','order' => 'DESC'); 完整循环: <?php $args
$args = array( 'posts_per_page' => 4, 'post_type' => 'product','meta_key' => '_featured','meta_value' => 'instock','orderby' =>'rand','order' => 'DESC');
完整循环:
<?php
$args = array( 'posts_per_page' => 4, 'post_type' => 'product','meta_key' => '_featured','meta_value' => 'instock','orderby' =>'rand','order' => 'DESC');
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
$product = new WC_Product( get_the_ID() );
$price = $product->price;
?>
<div class="col-sm-6 col-md-3">
<div class="thumbnail Product_Box">
<a href="<?php the_permalink()?>"><?php the_post_thumbnail();?></a>
<div class="caption">
<h4><?php the_title()?><br />
<span class="text-color">$<?php echo $price; ?></span></h4>
</div>
</div>
</div>
<?php endforeach;
wp_reset_postdata();?>
$
我想这就是你想要的:
$args = array(
'posts_per_page' => 4,
'post_type' => 'product',
'meta_key' => '_featured',
'orderby' =>'rand',
'order' => 'DESC',
'meta_value' => array(
array(
'key' => '_stock_status',
'value' => 'outofstock',
'compare' => '!='
)
);
如果启用了库存管理,则只需勾选复选框:),除非您想按代码方式操作 在电子商务->设置->产品->库存(选项卡)中,勾选缺货可见性复选框
您缺少关闭第一个数组:
'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => '!=' ) ) “元查询”=>数组( 排列( '键'=>''库存状况', 'value'=>'outofstock', '比较'=>'!=' ) )
那个循环有什么问题?它会产生什么结果?@Howlin我已经把整个循环上升了-没有meta_u键,它也可以正常工作-也显示了产品不在库存,我也厌倦了不使用相同的结果,没有什么你有能力拉的库存数量的项目?或者它存储在post meta某处?+1中,但键
meta\u值
需要替换为meta\u查询
,