Last active
June 21, 2019 22:44
-
-
Save rickalday/affc8390f961df043c30c3e7370d3e64 to your computer and use it in GitHub Desktop.
WooCommerce Category and Product listing
This file contains hidden or 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
$args = array( | |
'number' => $number, | |
'orderby' => 'title', | |
'order' => 'ASC', | |
'hide_empty' => $hide_empty, | |
'include' => $ids | |
); | |
$product_categories = get_terms( 'product_cat', $args ); | |
$count = count($product_categories); | |
if ( $count > 0 ){ | |
foreach ( $product_categories as $product_category ) { | |
echo '<h2><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h4>'; | |
$args = array( | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => $product_category->slug | |
) | |
), | |
'post_type' => 'product', | |
'orderby' => 'title,' | |
); | |
$products = new WP_Query( $args ); | |
echo "<ul>"; | |
while ( $products->have_posts() ) { | |
$products->the_post(); | |
?> | |
<li> | |
<a href="<?php the_permalink(); ?>"> | |
<?php the_title(); ?> | |
</a> | |
</li> | |
<?php | |
} | |
echo "</ul>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment