Woocommerce : exclude one category next/previous post buton

152 views Asked by At

I am preparing my shop with Woocommerce, I would like to add on the page of a product the possibility to go to the previous product and next. But only in the current category (main products) excluding the category of secondary products.

This is what I coded based on the wordpress codex :

<?php $previous_post = get_previous_post($in_same_term = true, 
$excluded_terms = '43', $taxonomy = 'product_cat'); if (!empty( 
$previous_post )): ?>
    <a href="<?php echo get_permalink( $previous_post->ID ); ?>">
      <?php echo $previous_post->post_title; ?>
    </a>
<?php endif; ?>

Unfortunately items in the secondary category continue to be offered.. Thank you for your help!

1

There are 1 answers

1
Sourabh On
please try as follow :

<?php $previous_post = get_previous_post($in_same_term = true, 
$excluded_terms = array('43'), $taxonomy = 'product_cat'); if (!empty( 
$previous_post )): ?>
    <a href="<?php echo get_permalink( $previous_post->ID ); ?>">
      <?php echo $previous_post->post_title; ?>
    </a>