Last active
September 30, 2020 11:23
-
-
Save rustam-swe/4898e0a8b4ec05571a1410bf2848ff34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gets all products by category ID | |
* Original source: https://wordpress.stackexchange.com/questions/143582/get-the-product-list-of-a-given-category-id | |
*/ | |
<ul class="relatedlinks"> | |
<?php | |
$args = [ | |
'post_type' => 'product', | |
'posts_per_page' => -1, | |
'post_status' => 'publish', | |
'tax_query' => [ | |
[ | |
'taxonomy' => 'product_cat', | |
'terms' => $product_category_id | |
] | |
] | |
]; | |
$related_products = new WP_Query($args); | |
if ($related_products) { | |
while ($related_products->have_posts()): | |
$related_products->the_post(); | |
?> | |
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> | |
<?php | |
endwhile; | |
wp_reset_postdata(); | |
} | |
?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment