【发布时间】:2017-09-20 16:40:29
【问题描述】:
在 WooCommerce 中,我使用脚本来显示一些随机产品,但现在我需要排除一个我不需要出现在本节中的产品类别。
如何在我的代码中做到这一点?
我的代码:
<?php
global $product;
$args = array(
'posts_per_page' => 4,
'orderby' => 'rand',
'post_type' => 'product'
);
$random_products = get_posts( $args );
foreach ( $random_products as $post ) : setup_postdata( $post ); ?>
<li class="single_product_lower_widget" style="list-style:none;">
<a href="<?php the_permalink(); ?>">
<span class="single_product_lower_widget_image">
<?php the_post_thumbnail() ?>
<span class="product-title"><?php the_title(); ?></span>
</span>
<p><?php get_post_meta( $post->ID, '_price', true ); ?></p>
</a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
【问题讨论】:
标签: php wordpress woocommerce categories product