Skip to content

Instantly share code, notes, and snippets.

@rustam-swe
Created September 30, 2020 16:53
Show Gist options
  • Save rustam-swe/c535ad4d829d2e888fb605f75485f410 to your computer and use it in GitHub Desktop.
Save rustam-swe/c535ad4d829d2e888fb605f75485f410 to your computer and use it in GitHub Desktop.
<?php
// TODO: ecplain what does this code
$tags = wp_get_post_terms($product_id, 'product_tag');
$tag_slug = [];
?>
<?php if ($tags) :
foreach ($tags as $tag) {
$tag_slug[] = $tag->slug;
}
$args = [
'post__not_in' => [$product_id],
'post_type' => 'product',
'product_tag' => $tag_slug
];
$related_products = new WP_Query($args);
?>
<div class="col-12">
<div class="rounded_panel mt70">
<h2>Related resources</h2>
<div class="row">
<div class="col-12 ">
<ul class="relatedlinks">
<?php if ($related_products) : ?>
<?php while ($related_products->have_posts()): ?>
<?php $related_products->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</ul>
</div>
</div>
</div>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment