I am trying to use the Woocommerce category taxonomy to display relevant products on a page. The custom post type allows me to add the product category list to the custom page but I am not sure how to filter it to only show the category I select for the respective page. At the moment it is showing all my products, not filtering the ones I need:
$args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'taxonomy' => 'product_cat' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<div class="background-img"><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().'<br /> '.get_the_title().'</a>';
echo $product->get_price_html();
echo '<form class="cart" method="post" enctype="multipart/form-data">
<input type="hidden" name="add-to-cart" value="';
echo esc_attr($product->id);
echo '">
<button type="submit">';
echo $product->single_add_to_cart_text();
echo '</button>
</form>';
echo '</div>';
endwhile;
$attachment_ids = $product->get_gallery_attachment_ids();
foreach( $attachment_ids as $attachment_id )
{
echo $image_link = wp_get_attachment_url( $attachment_id );
}
wp_reset_query();
Here is a version of the dev site, it is still quite raw and needs alot of styling but should give an idea:
I'm using the following plugin:
I can create a custom taxonomy but it is an extra step and produces the same results. I think I may be missing something small but I'm just not getting it.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire