How to list all products using Shopp
-
15-06-2021 - |
Question
Just trying to get a list of all products using the Shopp plugin for Wordpress. What am I missing? I can get a list of categories, and all products in each category, but products that aren't categorised don't appear.
Here's what I've got:
<?php
$cats = shopp_product_categories();
$dropdown = array();
foreach ( $cats as $cat ) :
$dropdown[$cat->slug]['group_name'] = $cat->name;
$dropdown[$cat->slug]['group_items'] = shopp_category_products( $cat->id );
endforeach;
?>
I'd also like to add a $dropdown['uncategorized']['group_items'] with an array of uncategorised items.
Thanks in advance!
Solution 2
I figured it out. :)
It ended up looking like this:
$cats = shopp_product_categories();
$cat_ids = array();
$dropdown = array();
foreach ( $cats as $cat ) :
$cat_ids[] = $cat->id;
$dropdown[$cat->slug]['group_name'] = $cat->name;
$dropdown[$cat->slug]['group_items'] = shopp_category_products( $cat->id );
endforeach;
$products = new WP_Query( array(
'post_type' => 'shopp_product',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'shopp_category',
'field' => 'id',
'terms' => $cat_ids,
'operator' => 'NOT IN'
)
)
) );
$dropdown['uncategorized']['group_name'] = 'Uncategorized';
while ( $products->have_posts() ) : $products->the_post();
$dropdown['uncategorized']['group_items'][] = array(
'id' => get_the_ID(),
'name' => get_the_title()
);
endwhile;
OTHER TIPS
This simple solution worked great for me:
<?php shopp('storefront','catalog-products','load=true&show=999'); if ( shopp('collection','has-products') ) { while ( shopp('collection','products') ) { ?><a href="<?php shopp('product','url'); ?>"><?php shopp('product','name'); ?></a><?php } } ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow