【发布时间】:2019-02-06 08:06:21
【问题描述】:
我想从循环中排除我当前帖子的类别。通常很容易,这次它不起作用,我无法弄清楚这里出了什么问题。
这是我的页面代码:
$postid = get_the_ID(); // curret product ID
<section class="related products">
<?php
$args = array(
'post__not_in' => array($postid), // Exclude displayed product
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '6',
'cat' => '-33' // Exclude cat
);
$related_products = new WP_Query($args);
?>
<h2><?php esc_html_e( 'Related products' ); ?></h2>
<div class="owl-carousel rigid-owl-carousel" >
<?php if( $related_products->have_posts() ) {
while( $related_products->have_posts() ) : $related_products->the_post();
wc_get_template_part( 'content', 'product' );
endwhile; }
?>
</section>
页面结束
<?php
wp_reset_postdata();
?>
它显示了所有产品(除了显示的产品,这是正确的)。
你有什么建议吗?
【问题讨论】:
标签: php wordpress woocommerce custom-taxonomy